-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Fix shadowing warning (2519) to cover inherited state variables #16800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AdrianMtzTrev
wants to merge
1
commit into
argotorg:develop
Choose a base branch
from
AdrianMtzTrev:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
11 changes: 11 additions & 0 deletions
11
...libsolidity/syntaxTests/scoping/name_shadowing_abstract_base_inherited_state_variable.sol
This file contains hidden or 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,11 @@ | ||
| abstract contract Base { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add more tests (or rather repurpose some of these) covering:
|
||
| uint256 value = 10; | ||
| } | ||
| contract Child is Base { | ||
| function f() public pure returns (uint256) { | ||
| uint256 value = 99; | ||
| return value; | ||
| } | ||
| } | ||
| // ---- | ||
| // Warning 2519: (133-146): This declaration shadows an existing declaration. | ||
10 changes: 10 additions & 0 deletions
10
...ity/syntaxTests/scoping/name_shadowing_function_parameter_vs_inherited_state_variable.sol
This file contains hidden or 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,10 @@ | ||
| contract Base { | ||
| uint256 value = 10; | ||
| } | ||
| contract Child is Base { | ||
| function f(uint256 value) public pure returns (uint256) { | ||
| return value; | ||
| } | ||
| } | ||
| // ---- | ||
| // Warning 2519: (82-95): This declaration shadows an existing declaration. |
11 changes: 11 additions & 0 deletions
11
...olidity/syntaxTests/scoping/name_shadowing_local_variable_vs_inherited_state_variable.sol
This file contains hidden or 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,11 @@ | ||
| contract Base { | ||
| uint256 value = 10; | ||
| } | ||
| contract Child is Base { | ||
| function f() public pure returns (uint256) { | ||
| uint256 value = 99; | ||
| return value; | ||
| } | ||
| } | ||
| // ---- | ||
| // Warning 2519: (124-137): This declaration shadows an existing declaration. |
10 changes: 10 additions & 0 deletions
10
...bsolidity/syntaxTests/scoping/name_shadowing_named_return_vs_inherited_state_variable.sol
This file contains hidden or 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,10 @@ | ||
| contract Base { | ||
| uint256 value = 10; | ||
| } | ||
| contract Child is Base { | ||
| function f() public pure returns (uint256 value) { | ||
| return 42; | ||
| } | ||
| } | ||
| // ---- | ||
| // Warning 2519: (105-118): This declaration shadows an existing declaration. |
12 changes: 12 additions & 0 deletions
12
test/libsolidity/syntaxTests/scoping/name_shadowing_transitive_inheritance.sol
This file contains hidden or 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,12 @@ | ||
| contract A { | ||
| uint256 value = 10; | ||
| } | ||
| contract B is A {} | ||
| contract C is B { | ||
| function f() public pure returns (uint256) { | ||
| uint256 value = 99; | ||
| return value; | ||
| } | ||
| } | ||
| // ---- | ||
| // Warning 2519: (133-146): This declaration shadows an existing declaration. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in the right direction, but since
resolveNamesAndTypesruns before, the inherited members are registered more than once byimportInheritedScope().When in the the derived contract the member is visible unqualified, it will be appended as a homonym candidate referencing the base member declaration (see
DeclarationContainer::registerDeclaration()).Before the changes made in this PR, the candidates were added after
warnHomonymDeclarations()had already run, so there was no duplicate warning.This is the cause of the two failing tests,
syntaxTests/errors/error_selector_syntax.solandsyntaxTests/multiSource/free_function_resolution_override_virtual.sol.So we need to mitigate this somehow, avoiding the repeated warnings for the same member.