diff --git a/slither/core/expressions/tuple_expression.py b/slither/core/expressions/tuple_expression.py index 1fd8fc7956..1515d84649 100644 --- a/slither/core/expressions/tuple_expression.py +++ b/slither/core/expressions/tuple_expression.py @@ -4,15 +4,21 @@ class TupleExpression(Expression): - def __init__(self, expressions: List[Expression]) -> None: + def __init__(self, expressions: List[Expression], is_inline_array: bool = False) -> None: assert all(isinstance(x, Expression) for x in expressions if x) super().__init__() self._expressions = expressions + self._is_inline_array = is_inline_array @property def expressions(self) -> List[Expression]: return self._expressions + @property + def is_inline_array(self) -> bool: + return self._is_inline_array + def __str__(self) -> str: expressions_str = [str(e) for e in self.expressions] - return "(" + ",".join(expressions_str) + ")" + l_bracket, r_bracket = ("[","]") if self._is_inline_array else ("(",")") + return l_bracket + ",".join(expressions_str) + r_bracket diff --git a/slither/solc_parsing/expressions/expression_parsing.py b/slither/solc_parsing/expressions/expression_parsing.py index 9e3a12b063..be211f1729 100644 --- a/slither/solc_parsing/expressions/expression_parsing.py +++ b/slither/solc_parsing/expressions/expression_parsing.py @@ -340,7 +340,7 @@ def parse_expression(expression: Dict, caller_context: CallerContextExpression) for idx, _ in enumerate(elems): if elems[idx] == "": expressions.insert(idx, None) - t = TupleExpression(expressions) + t = TupleExpression(expressions, is_inline_array=expression.get("isInlineArray", False)) t.set_offset(src, caller_context.compilation_unit) return t diff --git a/slither/visitors/slithir/expression_to_slithir.py b/slither/visitors/slithir/expression_to_slithir.py index 6b7b4c2645..09d626c986 100644 --- a/slither/visitors/slithir/expression_to_slithir.py +++ b/slither/visitors/slithir/expression_to_slithir.py @@ -510,7 +510,13 @@ def _post_new_elementary_type(self, expression): def _post_tuple_expression(self, expression): expressions = [get(e) if e else None for e in expression.expressions] - if len(expressions) == 1: + if expression.is_inline_array: + temp_var = TemporaryVariable(self._node) + init_arr = InitArray(expressions, temp_var) + self._result.append(init_arr) + # Use the new temporary variable in place of the array. + val = temp_var + elif len(expressions) == 1: val = expressions[0] else: val = expressions