Add support for "selector" access on custom error (#984)

* Add support for "selector" access on custom error
pull/987/head
Feist Josselin 3 years ago committed by GitHub
parent df1062902f
commit adfffbf40c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      slither/slithir/convert.py
  2. 3
      slither/slithir/operations/member.py
  3. BIN
      tests/ast-parsing/compile/custom_error-0.8.0-compact.zip
  4. BIN
      tests/ast-parsing/compile/custom_error-0.8.1-compact.zip
  5. BIN
      tests/ast-parsing/compile/custom_error-0.8.10-compact.zip
  6. BIN
      tests/ast-parsing/compile/custom_error-0.8.2-compact.zip
  7. BIN
      tests/ast-parsing/compile/custom_error-0.8.3-compact.zip
  8. BIN
      tests/ast-parsing/compile/custom_error-0.8.4-compact.zip
  9. BIN
      tests/ast-parsing/compile/custom_error-0.8.5-compact.zip
  10. BIN
      tests/ast-parsing/compile/custom_error-0.8.6-compact.zip
  11. BIN
      tests/ast-parsing/compile/custom_error-0.8.7-compact.zip
  12. BIN
      tests/ast-parsing/compile/custom_error-0.8.8-compact.zip
  13. BIN
      tests/ast-parsing/compile/custom_error-0.8.9-compact.zip
  14. 4
      tests/ast-parsing/custom_error-0.8.4.sol

@ -623,7 +623,19 @@ def propagate_types(ir, node: "Node"): # pylint: disable=too-many-locals
b.set_expression(ir.expression)
b.set_node(ir.node)
return b
if ir.variable_right == "selector" and isinstance(ir.variable_left.type, Function):
if ir.variable_right == "selector" and isinstance(ir.variable_left, (CustomError)):
assignment = Assignment(
ir.lvalue,
Constant(str(get_function_id(ir.variable_left.solidity_signature))),
ElementaryType("bytes4"),
)
assignment.set_expression(ir.expression)
assignment.set_node(ir.node)
assignment.lvalue.set_type(ElementaryType("bytes4"))
return assignment
if ir.variable_right == "selector" and isinstance(
ir.variable_left.type, (Function)
):
assignment = Assignment(
ir.lvalue,
Constant(str(get_function_id(ir.variable_left.type.full_name))),

@ -1,4 +1,5 @@
from slither.core.declarations import Contract, Function
from slither.core.declarations.custom_error import CustomError
from slither.core.declarations.enum import Enum
from slither.core.declarations.solidity_import_placeholder import SolidityImportPlaceHolder
from slither.slithir.operations.lvalue import OperationWithLValue
@ -21,7 +22,7 @@ class Member(OperationWithLValue):
# }
# }
assert is_valid_rvalue(variable_left) or isinstance(
variable_left, (Contract, Enum, Function, SolidityImportPlaceHolder)
variable_left, (Contract, Enum, Function, CustomError, SolidityImportPlaceHolder)
)
assert isinstance(variable_right, Constant)

@ -37,5 +37,9 @@ contract B is A{
function g() public{
revert MyError(2);
}
function h() public returns(bytes4){
return MyError.selector;
}
}

Loading…
Cancel
Save