Skip to content

Commit

Permalink
fmt and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
0xalpharush committed Mar 29, 2024
1 parent f04a3c1 commit 53c769d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
21 changes: 12 additions & 9 deletions slither/slithir/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,10 @@ def convert_constant_types(irs: List[Operation]) -> None:
was_changed = False
for ir in irs:
if isinstance(ir, (Assignment, Binary)):
if isinstance(ir.lvalue.type, ElementaryType) and ir.lvalue.type.type in ElementaryTypeInt:
if (
isinstance(ir.lvalue.type, ElementaryType)
and ir.lvalue.type.type in ElementaryTypeInt
):
for r in ir.read:
if isinstance(r, Constant) and r.type.type not in ElementaryTypeInt:
r.set_type(ElementaryType(ir.lvalue.type.type))
Expand All @@ -1943,7 +1946,7 @@ def convert_constant_types(irs: List[Operation]) -> None:
if arg.type.type not in ElementaryTypeInt:
arg.set_type(ElementaryType(t.type))
was_changed = True

if isinstance(ir, NewStructure):
st = ir.structure
for idx, arg in enumerate(ir.arguments):
Expand All @@ -1956,15 +1959,15 @@ def convert_constant_types(irs: List[Operation]) -> None:

def is_elementary_array(t):
return isinstance(t, ArrayType) and isinstance(t.type, ElementaryType)

if isinstance(ir, InitArray):
if is_elementary_array(ir.lvalue.type):
if ir.lvalue.type.type.type in ElementaryTypeInt:
for r in ir.read:
if isinstance(r, Constant) and is_elementary_array(r.type):
if r.type.type.type not in ElementaryTypeInt:
r.set_type(ElementaryType(ir.lvalue.type.type.type))
was_changed = True
if ir.lvalue.type.type.type in ElementaryTypeInt:
for r in ir.read:
if isinstance(r, Constant) and is_elementary_array(r.type):
if r.type.type.type not in ElementaryTypeInt:
r.set_type(ElementaryType(ir.lvalue.type.type.type))
was_changed = True


# endregion
Expand Down
1 change: 0 additions & 1 deletion slither/slithir/operations/init_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from slither.slithir.utils.utils import is_valid_rvalue, RVALUE
from slither.slithir.variables.temporary import TemporaryVariable
from slither.slithir.variables.temporary_ssa import TemporaryVariableSSA
from slither.slithir.utils.utils import RVALUE


class InitArray(OperationWithLValue):
Expand Down
2 changes: 1 addition & 1 deletion slither/visitors/slithir/expression_to_slithir.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def _post_call_expression(self, expression: CallExpression) -> None:
set_val(expression, val)

def _post_conditional_expression(self, expression: ConditionalExpression) -> None:
raise Exception(f"Ternary operator are not convertible to SlithIR {expression}")
raise SlithIRError(f"Ternary operator are not convertible to SlithIR {expression}")

def _post_elementary_type_name_expression(
self,
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/slithir/test_ssa_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,7 @@ def test_issue_2016(slither_from_solidity_source):
assert lvalue_type.type == ElementaryType("int256")
assert lvalue_type.is_dynamic


def test_issue_2210(slither_from_solidity_source):
source = """
contract C {
Expand All @@ -1162,7 +1163,7 @@ def test_issue_2210(slither_from_solidity_source):
assert isinstance(lvalue_type, ArrayType)
assert lvalue_type.type == ElementaryType("int256")
assert not lvalue_type.is_dynamic

source2 = """
contract X {
function _toInts(uint256[] memory a) private pure returns (int256[] memory casted) {
Expand All @@ -1185,8 +1186,8 @@ def test_issue_2210(slither_from_solidity_source):
assert isinstance(lvalue_type, ArrayType)
assert lvalue_type.type == ElementaryType("int256")
assert lvalue_type.is_dynamic

rvalue_type = new_op2.rvalue.type
assert isinstance(rvalue_type, ArrayType)
assert rvalue_type.type == ElementaryType("uint256")
assert rvalue_type.is_dynamic
assert rvalue_type.is_dynamic

0 comments on commit 53c769d

Please sign in to comment.