Array length: store the result of the constant folding in a separate variable to keep origin expression

pull/169/head
Josselin 6 years ago
parent 6c2923f254
commit 1073a04e90
  1. 15
      slither/core/solidity_types/array_type.py

@ -12,13 +12,18 @@ class ArrayType(Type):
if isinstance(length, int): if isinstance(length, int):
length = Literal(length) length = Literal(length)
assert isinstance(length, Expression) assert isinstance(length, Expression)
if not isinstance(length, Literal):
cf = ConstantFolding(length)
length = cf.result()
super(ArrayType, self).__init__() super(ArrayType, self).__init__()
self._type = t self._type = t
self._length = length self._length = length
if length:
if not isinstance(length, Literal):
cf = ConstantFolding(length)
length = cf.result()
self._length_value = length
else:
self._length_value = None
@property @property
def type(self): def type(self):
return self._type return self._type
@ -29,9 +34,7 @@ class ArrayType(Type):
def __str__(self): def __str__(self):
if self._length: if self._length:
if isinstance(self._length.value, Variable) and self._length.value.is_constant: return str(self._type)+'[{}]'.format(str(self._length_value))
return str(self._type)+'[{}]'.format(str(self._length.value.expression))
return str(self._type)+'[{}]'.format(str(self._length))
return str(self._type)+'[]' return str(self._type)+'[]'

Loading…
Cancel
Save