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
4 changes: 2 additions & 2 deletions libsolidity/interface/CompilerStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,6 @@ bool CompilerStack::analyze()
if (source->ast && !resolver.performImports(*source->ast, sourceUnitsByName))
return false;

resolver.warnHomonymDeclarations();

{
DocStringTagParser docStringTagParser(m_errorReporter);
for (Source const* source: m_sourceOrder)
Expand All @@ -518,6 +516,8 @@ bool CompilerStack::analyze()
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.


if (experimentalSolidity)
{
if (!analyzeExperimental())
Expand Down
Original file line number Diff line number Diff line change
@@ -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)

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.
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.
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.
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.
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.