Add support for NewArray in ternary split (close #79)

Fix dupplicate assignment during ternary split
pull/84/head
Josselin 6 years ago
parent 24ce3a76f8
commit 4d9062a6e3
  1. 5
      slither/solc_parsing/declarations/function.py
  2. 4
      slither/utils/expression_manipulations.py

@ -14,6 +14,7 @@ from slither.solc_parsing.variables.variable_declaration import MultipleVariable
from slither.solc_parsing.expressions.expression_parsing import parse_expression
from slither.core.expressions import AssignmentOperation
from slither.visitors.expression.export_values import ExportValues
from slither.visitors.expression.has_conditional import HasConditional
@ -848,12 +849,16 @@ class FunctionSolc(Function):
true_node = self._new_node(node.type, node.source_mapping)
if node.type == NodeType.VARIABLE:
true_node.add_variable_declaration(node.variable_declaration)
assert isinstance(true_expr, AssignmentOperation)
true_expr = true_expr.expression_right
true_node.add_expression(true_expr)
true_node.analyze_expressions(self)
false_node = self._new_node(node.type, node.source_mapping)
if node.type == NodeType.VARIABLE:
false_node.add_variable_declaration(node.variable_declaration)
assert isinstance(false_expr, AssignmentOperation)
false_expr = false_expr.expression_right
false_node.add_expression(false_expr)
false_node.analyze_expressions(self)

@ -66,7 +66,7 @@ class SplitTernaryExpression(object):
if isinstance(expression, ConditionalExpression):
raise Exception('Nested ternary operator not handled')
if isinstance(expression, (Literal, Identifier, IndexAccess)):
if isinstance(expression, (Literal, Identifier, IndexAccess, NewArray)):
return None
# case of lib
@ -117,5 +117,5 @@ class SplitTernaryExpression(object):
false_expression.expression)
else:
raise Exception('Ternary operation not handled {}'.format(type(expression)))
raise Exception('Ternary operation not handled {}({})'.format(expression, type(expression)))

Loading…
Cancel
Save