diff --git a/slither/core/expressions/tuple_expression.py b/slither/core/expressions/tuple_expression.py index 1fd8fc795..1515d8464 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 4991984ff..f0c326f65 100644 --- a/slither/solc_parsing/expressions/expression_parsing.py +++ b/slither/solc_parsing/expressions/expression_parsing.py @@ -386,7 +386,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 0f91f9bd1..8ade1aa86 100644 --- a/slither/visitors/slithir/expression_to_slithir.py +++ b/slither/visitors/slithir/expression_to_slithir.py @@ -700,7 +700,13 @@ def _post_new_elementary_type(self, expression: NewElementaryType) -> None: def _post_tuple_expression(self, expression: TupleExpression) -> None: all_expressions = [get(e) if e else None for e in expression.expressions] - if len(all_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(all_expressions) == 1: val = all_expressions[0] else: val = all_expressions