diff --git a/slither/visitors/slithir/expression_to_slithir.py b/slither/visitors/slithir/expression_to_slithir.py index d55dfb5890..e4fa5a1b18 100644 --- a/slither/visitors/slithir/expression_to_slithir.py +++ b/slither/visitors/slithir/expression_to_slithir.py @@ -626,7 +626,6 @@ def _post_unary_operation(self, expression: UnaryOperation) -> None: set_val(expression, value) elif expression.type in [UnaryOperationType.MINUS_PRE]: lvalue = TemporaryVariable(self._node) - assert isinstance(value.type, ElementaryType) operation = Binary(lvalue, Constant("0", value.type), value, BinaryType.SUBTRACTION) operation.set_expression(expression) self._result.append(operation) diff --git a/tests/e2e/solc_parsing/test_ast_parsing.py b/tests/e2e/solc_parsing/test_ast_parsing.py index 790f947cc1..a561343ded 100644 --- a/tests/e2e/solc_parsing/test_ast_parsing.py +++ b/tests/e2e/solc_parsing/test_ast_parsing.py @@ -452,6 +452,7 @@ def make_version(minor: int, patch_min: int, patch_max: int) -> List[str]: Test("yul-top-level-0.8.0.sol", ["0.8.0"]), Test("complex_imports/import_aliases_issue_1319/test.sol", ["0.5.12"]), Test("yul-state-constant-access.sol", ["0.8.16"]), + Test("negate-unary-element.sol", ["0.8.16"]), ] # create the output folder if needed try: diff --git a/tests/e2e/solc_parsing/test_data/compile/negate-unary-element.sol-0.8.16-compact.zip b/tests/e2e/solc_parsing/test_data/compile/negate-unary-element.sol-0.8.16-compact.zip new file mode 100644 index 0000000000..c18e5091b0 Binary files /dev/null and b/tests/e2e/solc_parsing/test_data/compile/negate-unary-element.sol-0.8.16-compact.zip differ diff --git a/tests/e2e/solc_parsing/test_data/expected/negate-unary-element.sol-0.8.16-compact.json b/tests/e2e/solc_parsing/test_data/expected/negate-unary-element.sol-0.8.16-compact.json new file mode 100644 index 0000000000..8381c16f7b --- /dev/null +++ b/tests/e2e/solc_parsing/test_data/expected/negate-unary-element.sol-0.8.16-compact.json @@ -0,0 +1,5 @@ +{ + "T": { + "a(int256[])": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: RETURN 1\n\"];\n}\n" + } +} \ No newline at end of file diff --git a/tests/e2e/solc_parsing/test_data/negate-unary-element.sol b/tests/e2e/solc_parsing/test_data/negate-unary-element.sol new file mode 100644 index 0000000000..b3f03c48d7 --- /dev/null +++ b/tests/e2e/solc_parsing/test_data/negate-unary-element.sol @@ -0,0 +1,5 @@ +contract T { + function a(int256[] memory data) public returns(int256) { + return -data[0]; + } +} \ No newline at end of file