Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check ElementaryTypeNameExpression in copy_expression #1306

Merged
merged 3 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion slither/utils/expression_manipulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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
Expand Down Expand Up @@ -80,7 +81,10 @@ def copy_expression(
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
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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"
}
}
7 changes: 7 additions & 0 deletions tests/ast-parsing/ternary-with-max.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
contract TernaryWithMax {
function f(
bool condition
) external returns(uint256 res) {
res = type(uint256).max / (condition ? 10 : 1) ;
}
}
1 change: 1 addition & 0 deletions tests/test_ast_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ def make_version(minor: int, patch_min: int, patch_max: int) -> List[str]:
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:
Expand Down