Fix shadowing warning (2519) to cover inherited state variables - #16800
Fix shadowing warning (2519) to cover inherited state variables#16800AdrianMtzTrev wants to merge 1 commit into
Conversation
matheusaaguiar
left a comment
There was a problem hiding this comment.
There is a problem with duplicated warnings for inherited members that should be addressed.
| @@ -0,0 +1,11 @@ | |||
| abstract contract Base { | |||
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
Sure, i'll take a look at this, thank you for the observation |
Moves warnHomonymDeclarations() after resolveNamesAndTypes() in CompilerStack.cpp.
Adds 5 syntax tests for inherited state variable shadowing:
Closes #16698