diff --git a/slither/utils/expression_manipulations.py b/slither/utils/expression_manipulations.py index 24d43299b..1a300c39b 100644 --- a/slither/utils/expression_manipulations.py +++ b/slither/utils/expression_manipulations.py @@ -9,6 +9,7 @@ from slither.core.expressions.assignment_operation import AssignmentOperation from slither.core.expressions.binary_operation import BinaryOperation from slither.core.expressions.call_expression import CallExpression from slither.core.expressions.conditional_expression import ConditionalExpression +from slither.core.expressions.elementary_type_name_expression import ElementaryTypeNameExpression from slither.core.expressions.expression import Expression from slither.core.expressions.identifier import Identifier from slither.core.expressions.index_access import IndexAccess @@ -80,7 +81,10 @@ class SplitTernaryExpression: if isinstance(expression, ConditionalExpression): raise SlitherException("Nested ternary operator not handled") - if isinstance(expression, (Literal, Identifier, IndexAccess, NewArray, NewContract)): + if isinstance( + expression, + (Literal, Identifier, IndexAccess, NewArray, NewContract, ElementaryTypeNameExpression), + ): return # case of lib diff --git a/tests/ast-parsing/compile/ternary-with-max.sol-0.8.15-compact.zip b/tests/ast-parsing/compile/ternary-with-max.sol-0.8.15-compact.zip new file mode 100644 index 000000000..dc4cb99da Binary files /dev/null and b/tests/ast-parsing/compile/ternary-with-max.sol-0.8.15-compact.zip differ diff --git a/tests/ast-parsing/expected/ternary-with-max.sol-0.8.15-compact.json b/tests/ast-parsing/expected/ternary-with-max.sol-0.8.15-compact.json new file mode 100644 index 000000000..755f83c9e --- /dev/null +++ b/tests/ast-parsing/expected/ternary-with-max.sol-0.8.15-compact.json @@ -0,0 +1,5 @@ +{ + "TernaryWithMax": { + "f(bool)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->2;\n2[label=\"Node Type: IF 2\n\"];\n2->3[label=\"True\"];\n2->4[label=\"False\"];\n3[label=\"Node Type: EXPRESSION 3\n\"];\n3->5;\n4[label=\"Node Type: EXPRESSION 4\n\"];\n4->5;\n5[label=\"Node Type: END_IF 5\n\"];\n}\n" + } +} \ No newline at end of file diff --git a/tests/ast-parsing/ternary-with-max.sol b/tests/ast-parsing/ternary-with-max.sol new file mode 100644 index 000000000..6eadf3cfd --- /dev/null +++ b/tests/ast-parsing/ternary-with-max.sol @@ -0,0 +1,7 @@ +contract TernaryWithMax { + function f( + bool condition + ) external returns(uint256 res) { + res = type(uint256).max / (condition ? 10 : 1) ; + } +} diff --git a/tests/test_ast_parsing.py b/tests/test_ast_parsing.py index ed83e2b20..15be1dd76 100644 --- a/tests/test_ast_parsing.py +++ b/tests/test_ast_parsing.py @@ -411,6 +411,7 @@ ALL_TESTS = [ Test("free_functions/libraries_from_free.sol", ["0.8.12"]), Test("free_functions/new_operator.sol", ["0.8.12"]), Test("free_functions/library_constant_function_collision.sol", ["0.8.12"]), + Test("ternary-with-max.sol", ["0.8.15"]), ] # create the output folder if needed try: