Skip to content

Commit

Permalink
Fix using for when used with "this" (#2224)
Browse files Browse the repository at this point in the history
  • Loading branch information
smonicas authored Feb 6, 2024
1 parent 9bf4d07 commit 6620bc9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
23 changes: 23 additions & 0 deletions slither/slithir/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,17 @@ def propagate_types(ir: Operation, node: "Node"): # pylint: disable=too-many-lo
if new_ir:
return new_ir

# convert library function when used with "this"
if (
isinstance(t, ElementaryType)
and t.name == "address"
and ir.destination.name == "this"
and UserDefinedType(node_function.contract) in using_for
):
new_ir = convert_to_library_or_top_level(ir, node, using_for)
if new_ir:
return new_ir

if isinstance(t, UserDefinedType):
# UserdefinedType
t_type = t.type
Expand Down Expand Up @@ -1564,6 +1575,18 @@ def convert_to_library_or_top_level(
if new_ir:
return new_ir

if (
isinstance(t, ElementaryType)
and t.name == "address"
and ir.destination.name == "this"
and UserDefinedType(node.function.contract) in using_for
):
new_ir = look_for_library_or_top_level(
contract, ir, using_for, UserDefinedType(node.function.contract)
)
if new_ir:
return new_ir

return None


Expand Down
1 change: 1 addition & 0 deletions tests/e2e/solc_parsing/test_ast_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ def make_version(minor: int, patch_min: int, patch_max: int) -> List[str]:
Test("using-for-functions-list-3-0.8.0.sol", ["0.8.15"]),
Test("using-for-functions-list-4-0.8.0.sol", ["0.8.15"]),
Test("using-for-global-0.8.0.sol", ["0.8.15"]),
Test("using-for-this-contract.sol", ["0.8.15"]),
Test("library_event-0.8.16.sol", ["0.8.16"]),
Test("top-level-struct-0.8.0.sol", ["0.8.0"]),
Test("yul-top-level-0.8.0.sol", ["0.8.0"]),
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Lib": {
"f(Hello)": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n}\n"
},
"Hello": {
"test()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n"
}
}
13 changes: 13 additions & 0 deletions tests/e2e/solc_parsing/test_data/using-for-this-contract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
library Lib {
function f(Hello h) external {

}
}
contract Hello {
using Lib for Hello;

function test() external {
this.f();
}
}

0 comments on commit 6620bc9

Please sign in to comment.