mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Do not warn about shadowing parameters in functions without implementation
This commit is contained in:
parent
edee67b4cc
commit
70b8b1c834
@ -120,11 +120,7 @@ bool DeclarationContainer::registerDeclaration(
|
||||
if (conflictingDeclaration(_declaration, _name))
|
||||
return false;
|
||||
|
||||
// Do not warn about shadowing for structs and enums because their members are
|
||||
// not accessible without prefixes. Also do not warn about event parameters
|
||||
// because they do not participate in any proper scope.
|
||||
bool special = _declaration.scope() && (_declaration.isStructMember() || _declaration.isEnumValue() || _declaration.isEventOrErrorParameter());
|
||||
if (m_enclosingContainer && !special)
|
||||
if (m_enclosingContainer && _declaration.isVisibleAsUnqualifiedName())
|
||||
m_homonymCandidates.emplace_back(*_name, _location ? _location : &_declaration.location());
|
||||
}
|
||||
|
||||
|
@ -606,6 +606,18 @@ bool Declaration::isEventOrErrorParameter() const
|
||||
return dynamic_cast<EventDefinition const*>(scope()) || dynamic_cast<ErrorDefinition const*>(scope());
|
||||
}
|
||||
|
||||
bool Declaration::isVisibleAsUnqualifiedName() const
|
||||
{
|
||||
if (!scope())
|
||||
return true;
|
||||
if (isStructMember() || isEnumValue() || isEventOrErrorParameter())
|
||||
return false;
|
||||
if (auto const* functionDefinition = dynamic_cast<FunctionDefinition const*>(scope()))
|
||||
if (!functionDefinition->isImplemented())
|
||||
return false; // parameter of a function without body
|
||||
return true;
|
||||
}
|
||||
|
||||
DeclarationAnnotation& Declaration::annotation() const
|
||||
{
|
||||
return initAnnotation<DeclarationAnnotation>();
|
||||
|
@ -265,6 +265,12 @@ public:
|
||||
/// @returns true if this is a declaration of a parameter of an event.
|
||||
bool isEventOrErrorParameter() const;
|
||||
|
||||
/// @returns false if the declaration can never be referenced without being qualified with a scope.
|
||||
/// Usually the name alone can be used to refer to the corresponding entity.
|
||||
/// But, for example, struct member names or enum member names always require a prefix.
|
||||
/// Another example is event parameter names, which do not participate in any proper scope.
|
||||
bool isVisibleAsUnqualifiedName() const;
|
||||
|
||||
/// @returns the type of expressions referencing this declaration.
|
||||
/// This can only be called once types of variable declarations have already been resolved.
|
||||
virtual Type const* type() const = 0;
|
||||
|
@ -0,0 +1,20 @@
|
||||
interface I {
|
||||
function f(uint I) external; // OK
|
||||
}
|
||||
|
||||
library L {
|
||||
function f(uint L) public pure {} // warning
|
||||
}
|
||||
|
||||
abstract contract A {
|
||||
function f(uint A) public pure {} // warning
|
||||
function g(uint A) public virtual; // OK
|
||||
}
|
||||
|
||||
contract C {
|
||||
function f(uint C) public pure {} // warning
|
||||
}
|
||||
// ----
|
||||
// Warning 2519: (91-97): This declaration shadows an existing declaration.
|
||||
// Warning 2519: (168-174): This declaration shadows an existing declaration.
|
||||
// Warning 2519: (283-289): This declaration shadows an existing declaration.
|
@ -0,0 +1,5 @@
|
||||
contract C {
|
||||
function f(uint f) pure public {}
|
||||
}
|
||||
// ----
|
||||
// Warning 2519: (28-34): This declaration shadows an existing declaration.
|
Loading…
Reference in New Issue
Block a user