Skip to content

Commit

Permalink
Change return type to UnaryType instead of UnaryOperationType (#2124)
Browse files Browse the repository at this point in the history
* fix: return UnaryType instead of UnaryOperationType for Unary IR operation (issue #2085)
  • Loading branch information
dokzai authored Sep 11, 2023
1 parent 8d5c033 commit d4950f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 2 additions & 3 deletions slither/slithir/operations/unary.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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
Expand Down Expand Up @@ -35,7 +34,7 @@ def __init__(
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)
Expand All @@ -53,7 +52,7 @@ def rvalue(self) -> Union[Constant, LocalVariable]:
return self._variable

@property
def type(self) -> UnaryOperationType:
def type(self) -> UnaryType:
return self._type

@property
Expand Down
10 changes: 9 additions & 1 deletion slither/visitors/slithir/expression_to_slithir.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
Member,
TypeConversion,
Unary,
UnaryType,
Unpack,
Return,
SolidityCall,
Expand Down Expand Up @@ -109,6 +110,13 @@ def set_val(expression: Expression, val: Any) -> None:
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,
Expand Down Expand Up @@ -585,7 +593,7 @@ def _post_unary_operation(self, expression: UnaryOperation) -> None:
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)
Expand Down

0 comments on commit d4950f7

Please sign in to comment.