diff --git a/slither/solc_parsing/expressions/expression_parsing.py b/slither/solc_parsing/expressions/expression_parsing.py index 759d3d6a2d..ff974a9fdd 100644 --- a/slither/solc_parsing/expressions/expression_parsing.py +++ b/slither/solc_parsing/expressions/expression_parsing.py @@ -445,6 +445,7 @@ def parse_expression(expression: Dict, caller_context: CallerContextExpression) t = expression["attributes"]["type"] if t: + found = re.findall("[struct|enum|function|modifier] \(([\[\] ()a-zA-Z0-9\.,_]*)\)", t) assert len(found) <= 1 if found: @@ -455,7 +456,6 @@ def parse_expression(expression: Dict, caller_context: CallerContextExpression) referenced_declaration = expression["referencedDeclaration"] else: referenced_declaration = None - var, was_created = find_variable(value, caller_context, referenced_declaration) if was_created: var.set_offset(src, caller_context.compilation_unit) diff --git a/slither/solc_parsing/solidity_types/type_parsing.py b/slither/solc_parsing/solidity_types/type_parsing.py index f052bba057..b77cc92ce9 100644 --- a/slither/solc_parsing/solidity_types/type_parsing.py +++ b/slither/solc_parsing/solidity_types/type_parsing.py @@ -272,8 +272,12 @@ def parse_type( all_structuress = [c.structures for c in scope.contracts.values()] all_structures = [item for sublist in all_structuress for item in sublist] all_structures += structures_direct_access + enums_direct_access = [] - all_enums = scope.enums.values() + all_enumss = [c.enums for c in scope.contracts.values()] + all_enums = [item for sublist in all_enumss for item in sublist] + all_enums += scope.enums.values() + contracts = scope.contracts.values() functions = list(scope.functions) diff --git a/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.4-compact.zip b/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.4-compact.zip index 913457a623..15e749a197 100644 Binary files a/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.4-compact.zip and b/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.4-compact.zip differ diff --git a/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.5-compact.zip b/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.5-compact.zip index 713a6a113b..070019e18a 100644 Binary files a/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.5-compact.zip and b/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.5-compact.zip differ diff --git a/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.6-compact.zip b/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.6-compact.zip index 2f3d091f86..e99b78ab69 100644 Binary files a/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.6-compact.zip and b/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.6-compact.zip differ diff --git a/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.7-compact.zip b/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.7-compact.zip index 97aa5d97af..42062d7081 100644 Binary files a/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.7-compact.zip and b/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.7-compact.zip differ diff --git a/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.8-compact.zip b/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.8-compact.zip index d97e8eb0ff..d11a080ffb 100644 Binary files a/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.8-compact.zip and b/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.8-compact.zip differ diff --git a/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.9-compact.zip b/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.9-compact.zip index f732869b3c..1b450a6e3f 100644 Binary files a/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.9-compact.zip and b/tests/ast-parsing/compile/custom_error-0.8.4.sol-0.8.9-compact.zip differ diff --git a/tests/ast-parsing/custom_error-0.8.4.sol b/tests/ast-parsing/custom_error-0.8.4.sol index d62f96e87e..ea185de89e 100644 --- a/tests/ast-parsing/custom_error-0.8.4.sol +++ b/tests/ast-parsing/custom_error-0.8.4.sol @@ -1,4 +1,8 @@ pragma solidity ^0.8.4; +interface I { + enum SomeEnum { ONE, TWO, THREE } + error ErrorWithEnum(SomeEnum e); +} struct St{ uint v; @@ -8,7 +12,8 @@ error ErrorSimple(); error ErrorWithArgs(uint, uint); error ErrorWithStruct(St s); -contract VendingMachine { + +contract VendingMachine is I { function err0() public { revert ErrorSimple(); @@ -19,10 +24,14 @@ contract VendingMachine { } function err2() public{ revert ErrorWithArgs(10+10, 10); + revert ErrorWithArgs(uint(SomeEnum.ONE), uint(SomeEnum.ONE)); } function err3() public{ revert('test'); } + function err4() public { + revert ErrorWithEnum(SomeEnum.ONE); + } } contract A{ @@ -43,3 +52,4 @@ contract B is A{ } } + diff --git a/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.4-compact.json b/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.4-compact.json index 995b49f834..0a90299792 100644 --- a/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.4-compact.json +++ b/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.4-compact.json @@ -1,9 +1,11 @@ { + "I": {}, "VendingMachine": { "err0()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", "err1()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: NEW VARIABLE 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n", - "err2()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", - "err3()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" + "err2()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n", + "err3()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", + "err4()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" }, "A": { "f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" diff --git a/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.5-compact.json b/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.5-compact.json index 995b49f834..0a90299792 100644 --- a/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.5-compact.json +++ b/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.5-compact.json @@ -1,9 +1,11 @@ { + "I": {}, "VendingMachine": { "err0()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", "err1()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: NEW VARIABLE 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n", - "err2()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", - "err3()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" + "err2()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n", + "err3()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", + "err4()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" }, "A": { "f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" diff --git a/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.6-compact.json b/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.6-compact.json index 995b49f834..0a90299792 100644 --- a/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.6-compact.json +++ b/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.6-compact.json @@ -1,9 +1,11 @@ { + "I": {}, "VendingMachine": { "err0()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", "err1()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: NEW VARIABLE 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n", - "err2()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", - "err3()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" + "err2()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n", + "err3()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", + "err4()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" }, "A": { "f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" diff --git a/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.7-compact.json b/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.7-compact.json index 995b49f834..0a90299792 100644 --- a/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.7-compact.json +++ b/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.7-compact.json @@ -1,9 +1,11 @@ { + "I": {}, "VendingMachine": { "err0()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", "err1()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: NEW VARIABLE 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n", - "err2()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", - "err3()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" + "err2()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n", + "err3()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", + "err4()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" }, "A": { "f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" diff --git a/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.8-compact.json b/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.8-compact.json index 995b49f834..0a90299792 100644 --- a/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.8-compact.json +++ b/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.8-compact.json @@ -1,9 +1,11 @@ { + "I": {}, "VendingMachine": { "err0()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", "err1()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: NEW VARIABLE 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n", - "err2()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", - "err3()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" + "err2()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n", + "err3()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", + "err4()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" }, "A": { "f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" diff --git a/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.9-compact.json b/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.9-compact.json index 995b49f834..0a90299792 100644 --- a/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.9-compact.json +++ b/tests/ast-parsing/expected/custom_error-0.8.4.sol-0.8.9-compact.json @@ -1,9 +1,11 @@ { + "I": {}, "VendingMachine": { "err0()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", "err1()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: NEW VARIABLE 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n", - "err2()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", - "err3()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" + "err2()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n1->2;\n2[label=\"Node Type: EXPRESSION 2\n\"];\n}\n", + "err3()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n", + "err4()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n" }, "A": { "f()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n"