Fix parsing of constants

Fixes: #1376
pull/1377/head
Emilio López 2 years ago
parent 01baf01860
commit 98611e3ae7
  1. 4
      slither/core/expressions/literal.py
  2. 2
      slither/core/solidity_types/array_type.py
  3. 7
      slither/visitors/expression/constants_folding.py

@ -2,6 +2,7 @@ from typing import Optional, Union, TYPE_CHECKING
from slither.core.expressions.expression import Expression
from slither.utils.arithmetic import convert_subdenomination
from slither.utils.integer_conversion import convert_string_to_int
if TYPE_CHECKING:
from slither.core.solidity_types.type import Type
@ -29,8 +30,7 @@ class Literal(Expression):
def __str__(self):
if self.subdenomination:
return str(convert_subdenomination(self._value, self.subdenomination))
# be sure to handle any character
return str(self._value)
return str(convert_string_to_int(self._value))
def __eq__(self, other):
if not isinstance(other, Literal):

@ -53,7 +53,7 @@ class ArrayType(Type):
def storage_size(self) -> Tuple[int, bool]:
if self._length_value:
elem_size, _ = self._type.storage_size
return elem_size * int(self._length_value.value), True
return elem_size * int(str(self._length_value)), True
return 32, True
def __str__(self):

@ -1,3 +1,4 @@
from decimal import Decimal, InvalidOperation
from slither.core.expressions import BinaryOperationType, Literal, UnaryOperationType
from slither.utils.integer_conversion import convert_string_to_int
from slither.visitors.expression.expression import ExpressionVisitor
@ -77,9 +78,9 @@ class ConstantFolding(ExpressionVisitor):
raise NotConstant
def _post_literal(self, expression):
if expression.value.isdigit():
set_val(expression, int(expression.value))
else:
try:
set_val(expression, Decimal(expression.value))
except InvalidOperation:
raise NotConstant
def _post_assignement_operation(self, expression):

Loading…
Cancel
Save