From d4950f7212cd323b78ed691f520f2ab5e881c6b6 Mon Sep 17 00:00:00 2001 From: judowoodo <38355190+dokzai@users.noreply.github.com> Date: Mon, 11 Sep 2023 14:00:40 -0400 Subject: [PATCH] Change return type to UnaryType instead of UnaryOperationType (#2124) * fix: return UnaryType instead of UnaryOperationType for Unary IR operation (issue #2085) --- slither/slithir/operations/unary.py | 5 ++--- slither/visitors/slithir/expression_to_slithir.py | 10 +++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/slither/slithir/operations/unary.py b/slither/slithir/operations/unary.py index c6493921d..72e7ac63a 100644 --- a/slither/slithir/operations/unary.py +++ b/slither/slithir/operations/unary.py @@ -5,7 +5,6 @@ from enum import Enum from slither.slithir.operations.lvalue import OperationWithLValue from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue from slither.slithir.exceptions import SlithIRError -from slither.core.expressions.unary_operation import UnaryOperationType from slither.core.variables.local_variable import LocalVariable from slither.slithir.variables.constant import Constant from slither.slithir.variables.local_variable import LocalIRVariable @@ -35,7 +34,7 @@ class Unary(OperationWithLValue): self, result: Union[TemporaryVariableSSA, TemporaryVariable], variable: Union[Constant, LocalIRVariable, LocalVariable], - operation_type: UnaryOperationType, + operation_type: UnaryType, ) -> None: assert is_valid_rvalue(variable) assert is_valid_lvalue(result) @@ -53,7 +52,7 @@ class Unary(OperationWithLValue): return self._variable @property - def type(self) -> UnaryOperationType: + def type(self) -> UnaryType: return self._type @property diff --git a/slither/visitors/slithir/expression_to_slithir.py b/slither/visitors/slithir/expression_to_slithir.py index a1dadbb63..9aca7f10c 100644 --- a/slither/visitors/slithir/expression_to_slithir.py +++ b/slither/visitors/slithir/expression_to_slithir.py @@ -50,6 +50,7 @@ from slither.slithir.operations import ( Member, TypeConversion, Unary, + UnaryType, Unpack, Return, SolidityCall, @@ -109,6 +110,13 @@ _binary_to_binary = { BinaryOperationType.OROR: BinaryType.OROR, } + +_unary_to_unary = { + UnaryOperationType.BANG: UnaryType.BANG, + UnaryOperationType.TILD: UnaryType.TILD, +} + + _signed_to_unsigned = { BinaryOperationType.DIVISION_SIGNED: BinaryType.DIVISION, BinaryOperationType.MODULO_SIGNED: BinaryType.MODULO, @@ -585,7 +593,7 @@ class ExpressionToSlithIR(ExpressionVisitor): operation: Operation if expression.type in [UnaryOperationType.BANG, UnaryOperationType.TILD]: lvalue = TemporaryVariable(self._node) - operation = Unary(lvalue, value, expression.type) + operation = Unary(lvalue, value, _unary_to_unary[expression.type]) operation.set_expression(expression) self._result.append(operation) set_val(expression, lvalue)