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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user