Skip to content

Commit

Permalink
fix ternary in nested expr with index access
Browse files Browse the repository at this point in the history
  • Loading branch information
0xalpharush committed Feb 9, 2023
1 parent 2caf510 commit 3bf8bfb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions slither/utils/expression_manipulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ def copy_expression(

if isinstance(
expression,
(Literal, Identifier, IndexAccess, NewArray, NewContract, ElementaryTypeNameExpression),
(Literal, Identifier, NewArray, NewContract, ElementaryTypeNameExpression),
):
return

if isinstance(expression, (AssignmentOperation, BinaryOperation, TupleExpression)):
if isinstance(
expression, (AssignmentOperation, BinaryOperation, TupleExpression, IndexAccess)
):
true_expression._expressions = []
false_expression._expressions = []
self.convert_expressions(expression, true_expression, false_expression)
Expand Down Expand Up @@ -137,8 +139,6 @@ def convert_expressions(
# TODO: can we get rid of `NoneType` expressions in `TupleExpression`?
# montyly: this might happen with unnamed tuple (ex: (,,,) = f()), but it needs to be checked
if next_expr:
if isinstance(next_expr, IndexAccess):
self.convert_index_access(next_expr, true_expression, false_expression)

if self.conditional_not_ahead(
next_expr, true_expression, false_expression, f_expressions
Expand Down
10 changes: 10 additions & 0 deletions tests/slithir/ternary_expressions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ contract C {
function g(address one) public {
(, uint x) = Test(one).testTuple();
}

uint[] myIntegers;
function _h(uint c) internal returns(uint) {
return c;
}
function h(bool cond, uint a, uint b) public {
uint d = _h(
myIntegers[cond ? a : b]
);
}
}

0 comments on commit 3bf8bfb

Please sign in to comment.