diff --git a/Changelog.md b/Changelog.md index 779aadbeb..61d079dda 100644 --- a/Changelog.md +++ b/Changelog.md @@ -15,6 +15,7 @@ Compiler Features: Bugfixes: * Type Checker: Disallow ``virtual`` for modifiers in libraries. + * Type Checker: Correct the warning for homonymous, but not shadowing declarations. * ViewPureChecker: Prevent visibility check on constructors. * Type system: Fix internal error on implicit conversion of contract instance to the type of its ``super``. * Type system: Fix named parameters in overloaded function and event calls being matched incorrectly if the order differs from the declaration. diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index ff3fdc6f9..990382aee 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -503,11 +503,20 @@ bool DeclarationRegistrationHelper::registerDeclaration( else { auto shadowedLocation = shadowedDeclaration->location(); - _errorReporter.warning( - 2519_error, - _declaration.location(), - "This declaration shadows an existing declaration.", - SecondarySourceLocation().append("The shadowed declaration is here:", shadowedLocation) + + if (!shadowedDeclaration->isVisibleInContract()) + _errorReporter.warning( + 8760_error, + _declaration.location(), + "This declaration has the same name as another declaration.", + SecondarySourceLocation().append("The other declaration is here:", shadowedLocation) + ); + else + _errorReporter.warning( + 2519_error, + _declaration.location(), + "This declaration shadows an existing declaration.", + SecondarySourceLocation().append("The shadowed declaration is here:", shadowedLocation) ); } } diff --git a/test/libsolidity/syntaxTests/scoping/name_pseudo_shadowing.sol b/test/libsolidity/syntaxTests/scoping/name_pseudo_shadowing.sol new file mode 100644 index 000000000..d2a191eeb --- /dev/null +++ b/test/libsolidity/syntaxTests/scoping/name_pseudo_shadowing.sol @@ -0,0 +1,6 @@ +contract test { + function e() external { } + function f() public pure { uint e; e = 0; } +} +// ---- +// Warning 8760: (77-83): This declaration has the same name as another declaration. diff --git a/test/libsolidity/syntaxTests/scoping/name_shadowing2.sol b/test/libsolidity/syntaxTests/scoping/name_shadowing2.sol new file mode 100644 index 000000000..b78184109 --- /dev/null +++ b/test/libsolidity/syntaxTests/scoping/name_shadowing2.sol @@ -0,0 +1,6 @@ +function e() {} +contract test { + function f() pure public { uint e; e = 0; } +} +// ---- +// Warning 2519: (63-69): This declaration shadows an existing declaration.