@@ -121,13 +121,7 @@ bool DeclarationContainer::registerDeclaration(
121121 if (conflictingDeclaration (_declaration, _name))
122122 return false ;
123123
124- // Do not warn about shadowing for structs and enums because their members are
125- // not accessible without prefixes. Also do not warn about event parameters
126- // because they do not participate in any proper scope.
127- FunctionDefinition const * functionDefinitionScope = dynamic_cast <FunctionDefinition const *>(_declaration.scope ());
128- bool special = (_declaration.scope () && (_declaration.isStructMember () || _declaration.isEnumValue () || _declaration.isEventParameter ())) ||
129- (functionDefinitionScope && !functionDefinitionScope->hasBody ()); // parameter of a function without body
130- if (m_enclosingContainer && !special)
124+ if (m_enclosingContainer && _declaration.isNameSelfSufficient ())
131125 m_homonymCandidates.emplace_back (*_name, _location ? _location : &_declaration.location ());
132126 }
133127
@@ -146,14 +140,28 @@ bool DeclarationContainer::registerDeclaration(
146140 return registerDeclaration (_declaration, nullptr , nullptr , _invisible, _update);
147141}
148142
149- vector<Declaration const *> DeclarationContainer::resolveName (ASTString const & _name, bool _recursive, bool _alsoInvisible) const
143+ vector<Declaration const *> DeclarationContainer::resolveName (
144+ ASTString const & _name,
145+ bool _recursive,
146+ bool _alsoInvisible,
147+ bool _onlySelfSufficientNames
148+ ) const
150149{
151150 solAssert (!_name.empty (), " Attempt to resolve empty name." );
152151 vector<Declaration const *> result;
152+
153+ auto filter = [&result, &_onlySelfSufficientNames](vector<Declaration const *> _declarations) {
154+ _onlySelfSufficientNames ?
155+ copy_if (_declarations.cbegin (), _declarations.cend (), back_inserter (result), [](auto & _declaration) {
156+ return _declaration->isNameSelfSufficient ();
157+ }) :
158+ copy (_declarations.cbegin (), _declarations.cend (), back_inserter (result));
159+ };
160+
153161 if (m_declarations.count (_name))
154- result = m_declarations.at (_name);
162+ filter ( m_declarations.at (_name) );
155163 if (_alsoInvisible && m_invisibleDeclarations.count (_name))
156- result += m_invisibleDeclarations.at (_name);
164+ filter ( m_invisibleDeclarations.at (_name) );
157165 if (result.empty () && _recursive && m_enclosingContainer)
158166 result = m_enclosingContainer->resolveName (_name, true , _alsoInvisible);
159167 return result;
0 commit comments