Skip to content

wake.ir.statements.revert_statement module #

RevertStatement class #

Bases: StatementAbc

Warning

Only matches reverts with user-defined errors:

revert InsufficientBalance(want, have);
This is an ExpressionStatement with a FunctionCall expression:
revert("Insufficient balance");

Source code in wake/ir/statements/revert_statement.py
class RevertStatement(StatementAbc):
    """
    !!! warning
        Only matches reverts with user-defined errors:
        ```solidity
        revert InsufficientBalance(want, have);
        ```
        This is an [ExpressionStatement][wake.ir.statements.expression_statement.ExpressionStatement] with a [FunctionCall][wake.ir.expressions.function_call.FunctionCall] expression:
        ```solidity
        revert("Insufficient balance");
        ```
    """

    _ast_node: SolcRevertStatement
    _parent: weakref.ReferenceType[
        Union[
            Block,
            DoWhileStatement,
            ForStatement,
            IfStatement,
            UncheckedBlock,
            WhileStatement,
        ]
    ]

    _error_call: FunctionCall

    def __init__(
        self, init: IrInitTuple, revert: SolcRevertStatement, parent: SolidityAbc
    ):
        super().__init__(init, revert, parent)
        self._error_call = FunctionCall(init, revert.error_call, self)

    def __iter__(self) -> Iterator[IrAbc]:
        yield self
        yield from self._error_call

    @property
    def parent(
        self,
    ) -> Union[
        Block,
        DoWhileStatement,
        ForStatement,
        IfStatement,
        UncheckedBlock,
        WhileStatement,
    ]:
        """
        Returns:
            Parent IR node.
        """
        return super().parent

    @property
    def children(self) -> Iterator[FunctionCall]:
        """
        Yields:
            Direct children of this node.
        """
        yield self._error_call

    @property
    def error_call(self) -> FunctionCall:
        """
        !!! example
            ```solidity
            InsufficientBalance(want, have)
            ```
            in the following revert statement:
            ```solidity
            revert InsufficientBalance(want, have)
            ```

        Returns:
            Expression representing the error call.
        """
        return self._error_call

    @property
    @weak_self_lru_cache(maxsize=2048)
    def modifies_state(
        self,
    ) -> Set[Tuple[Union[ExpressionAbc, StatementAbc, YulAbc], ModifiesStateFlag]]:
        return self.error_call.modifies_state

children: Iterator[FunctionCall] property #

Yields:

Type Description
FunctionCall

Direct children of this node.

error_call: FunctionCall property #

Example

InsufficientBalance(want, have)
in the following revert statement:
revert InsufficientBalance(want, have)

Returns:

Type Description
FunctionCall

Expression representing the error call.

parent: Union[Block, DoWhileStatement, ForStatement, IfStatement, UncheckedBlock, WhileStatement] property #

Returns:

Type Description
Union[Block, DoWhileStatement, ForStatement, IfStatement, UncheckedBlock, WhileStatement]

Parent IR node.