Do not warn about shadowing parameters in functions without implementation

This commit is contained in:
a3d4
2021-06-09 12:35:26 +02:00
committed by chriseth
parent edee67b4cc
commit 70b8b1c834
8 changed files with 44 additions and 5 deletions
@@ -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());
}
+12
View File
@@ -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>();
+6
View File
@@ -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;