Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions slither/solc_parsing/slither_compilation_unit_solc.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,30 @@ def parse_contracts(self) -> None:
if self._parsed:
raise Exception("Contract analysis can be run only once!")

def resolve_contract_from_scope(
scope: FileScope, contract_name: str, seen: set[FileScope] | None = None
) -> Contract | None:
seen = seen or set()
if scope in seen:
return None
seen.add(scope)

target = scope.get_contract_from_name(contract_name)
if target is not None:
return target

if contract_name in scope.renaming:
target = scope.get_contract_from_name(scope.renaming[contract_name])
if target is not None:
return target

for accessible_scope in scope.accessible_scopes:
target = resolve_contract_from_scope(accessible_scope, contract_name, seen)
if target is not None:
return target

return None

def resolve_remapping_and_renaming(contract_parser: ContractSolc, want: str) -> Contract:
contract_name = contract_parser.remapping[want]
target = None
Expand All @@ -475,8 +499,8 @@ def resolve_remapping_and_renaming(contract_parser: ContractSolc, want: str) ->
# Fallback to the current file scope if the contract is not found in the import path's scope.
# It is assumed that it isn't possible to defined a contract with the same name as "aliased" names.
if target is None:
target = contract_parser.underlying_contract.file_scope.get_contract_from_name(
contract_name
target = resolve_contract_from_scope(
contract_parser.underlying_contract.file_scope, contract_name
)

if target == contract_parser.underlying_contract:
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 @@ -432,6 +432,7 @@ def make_version(minor: int, patch_min: int, patch_max: int) -> list[str]:
),
Test("custom_error_with_state_variable.sol", make_version(8, 4, 12)),
Test("complex_imports/import_aliases/test.sol", VERSIONS_08),
Test("complex_imports/import_aliases_reexport/test.sol", ["0.8.35"]),
# 0.8.9 crashes on our testcase
Test(
"user_defined_value_type/user_defined_types-0.8.8.sol", ["0.8.8"] + make_version(8, 10, 15)
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import {Original as Alias} from "./Original.sol";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Original {
function run() external;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "./Alias.sol";

contract Child is Alias {
function run() external override {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Original": {
"run()": "digraph{\n}\n"
},
"Child": {
"run()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n}\n"
}
}