Skip to content

Fix shadowing warning (2519) to cover inherited state variables - #16800

Open
AdrianMtzTrev wants to merge 1 commit into
argotorg:developfrom
AdrianMtzTrev:develop
Open

Fix shadowing warning (2519) to cover inherited state variables#16800
AdrianMtzTrev wants to merge 1 commit into
argotorg:developfrom
AdrianMtzTrev:develop

Conversation

@AdrianMtzTrev

Copy link
Copy Markdown

Moves warnHomonymDeclarations() after resolveNamesAndTypes() in CompilerStack.cpp.

Adds 5 syntax tests for inherited state variable shadowing:

  • Local variable vs inherited state variable
  • Function parameter vs inherited state variable
  • Named return vs inherited state variable
  • Transitive inheritance (A -> B -> C)
  • Abstract base with inherited state variable

Closes #16698

@matheusaaguiar matheusaaguiar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a problem with duplicated warnings for inherited members that should be addressed.

@@ -0,0 +1,11 @@
abstract contract Base {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add more tests (or rather repurpose some of these) covering:

  • abstract contract
  • multi-source (imported contract from another source)
  • inherited state variable which is not on the topmost (e.g., contract C is B, contract B is A -> state var in contract B)

if (source->ast && !resolver.resolveNamesAndTypes(*source->ast))
return false;

resolver.warnHomonymDeclarations();

Copy link
Copy Markdown
Contributor

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 resolveNamesAndTypes runs before, the inherited members are registered more than once by importInheritedScope().
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.sol and syntaxTests/multiSource/free_function_resolution_override_virtual.sol.
So we need to mitigate this somehow, avoiding the repeated warnings for the same member.

@AdrianMtzTrev

Copy link
Copy Markdown
Author

There is a problem with duplicated warnings for inherited members that should be addressed.

Sure, i'll take a look at this, thank you for the observation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend shadowing warning to cover local variables that shadow inherited state variables

2 participants