-
Notifications
You must be signed in to change notification settings - Fork 980
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2121 from crytic/fix/prioritize-reference-id
prioritize reference id in name resolution to avoid shadowing issues
- Loading branch information
Showing
8 changed files
with
119 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
tests/unit/core/test_data/name_resolution/shadowing_compact.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pragma solidity 0.8.0; | ||
contract B { | ||
uint public x = 21; | ||
function a() public { | ||
uint u = 2 * x; | ||
uint x; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/unit/core/test_data/name_resolution/shadowing_legacy_post_0_5_0.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pragma solidity 0.5.0; | ||
contract B { | ||
uint public x = 21; | ||
function a() public { | ||
uint u = 2 * x; | ||
uint x; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/unit/core/test_data/name_resolution/shadowing_legacy_pre_0_5_0.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pragma solidity 0.4.12; | ||
contract B { | ||
uint public x = 21; | ||
function a() public { | ||
uint u = 2 * x; | ||
uint x; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from pathlib import Path | ||
|
||
from slither import Slither | ||
|
||
|
||
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" | ||
NAME_RESOLUTION_TEST_ROOT = Path(TEST_DATA_DIR, "name_resolution") | ||
|
||
|
||
def _sort_references_lines(refs: list) -> list: | ||
return sorted([ref.lines[0] for ref in refs]) | ||
|
||
|
||
def test_name_resolution_compact(solc_binary_path) -> None: | ||
solc_path = solc_binary_path("0.8.0") | ||
slither = Slither( | ||
Path(NAME_RESOLUTION_TEST_ROOT, "shadowing_compact.sol").as_posix(), solc=solc_path | ||
) | ||
contract = slither.get_contract_from_name("B")[0] | ||
x = contract.get_state_variable_from_name("x") | ||
assert _sort_references_lines(x.references) == [5] | ||
|
||
|
||
def test_name_resolution_legacy_post_0_5_0(solc_binary_path) -> None: | ||
solc_path = solc_binary_path("0.5.0") | ||
slither = Slither( | ||
Path(NAME_RESOLUTION_TEST_ROOT, "shadowing_legacy_post_0_5_0.sol").as_posix(), | ||
solc=solc_path, | ||
) | ||
contract = slither.get_contract_from_name("B")[0] | ||
x = contract.get_state_variable_from_name("x") | ||
assert _sort_references_lines(x.references) == [5] | ||
|
||
|
||
def test_name_resolution_legacy_pre_0_5_0(solc_binary_path) -> None: | ||
solc_path = solc_binary_path("0.4.12") | ||
slither = Slither( | ||
Path(NAME_RESOLUTION_TEST_ROOT, "shadowing_legacy_pre_0_5_0.sol").as_posix(), | ||
solc=solc_path, | ||
force_legacy=True, | ||
) | ||
contract = slither.get_contract_from_name("B")[0] | ||
function = contract.get_function_from_signature("a()") | ||
x = function.get_local_variable_from_name("x") | ||
assert _sort_references_lines(x.references) == [5] |