File tree Expand file tree Collapse file tree 4 files changed +30
-6
lines changed Expand file tree Collapse file tree 4 files changed +30
-6
lines changed Original file line number Diff line number Diff line change @@ -185,8 +185,18 @@ vector<Declaration const*> NameAndTypeResolver::nameFromCurrentScope(ASTString c
185
185
}
186
186
187
187
Declaration const * NameAndTypeResolver::pathFromCurrentScope (vector<ASTString> const & _path) const
188
+ {
189
+ if (auto declarations = pathFromCurrentScopeWithAllDeclarations (_path); !declarations.empty ())
190
+ return declarations.back ();
191
+
192
+ return nullptr ;
193
+ }
194
+
195
+ std::vector<Declaration const *> NameAndTypeResolver::pathFromCurrentScopeWithAllDeclarations (std::vector<ASTString> const & _path) const
188
196
{
189
197
solAssert (!_path.empty (), " " );
198
+ vector<Declaration const *> pathDeclarations;
199
+
190
200
vector<Declaration const *> candidates = m_currentScope->resolveName (
191
201
_path.front (),
192
202
/* _recursive */ true ,
@@ -197,13 +207,19 @@ Declaration const* NameAndTypeResolver::pathFromCurrentScope(vector<ASTString> c
197
207
for (size_t i = 1 ; i < _path.size () && candidates.size () == 1 ; i++)
198
208
{
199
209
if (!m_scopes.count (candidates.front ()))
200
- return nullptr ;
210
+ return {};
211
+
212
+ pathDeclarations.push_back (candidates.front ());
213
+
201
214
candidates = m_scopes.at (candidates.front ())->resolveName (_path[i], false );
202
215
}
203
216
if (candidates.size () == 1 )
204
- return candidates.front ();
217
+ {
218
+ pathDeclarations.push_back (candidates.front ());
219
+ return pathDeclarations;
220
+ }
205
221
else
206
- return nullptr ;
222
+ return {} ;
207
223
}
208
224
209
225
void NameAndTypeResolver::warnHomonymDeclarations () const
Original file line number Diff line number Diff line change @@ -93,6 +93,10 @@ class NameAndTypeResolver
93
93
// / Should only be called during the initial resolving phase.
94
94
// / @note Returns a null pointer if any component in the path was not unique or not found.
95
95
Declaration const * pathFromCurrentScope (std::vector<ASTString> const & _path) const ;
96
+ // / Resolves a path starting from the "current" scope, but also searches parent scopes.
97
+ // / Should only be called during the initial resolving phase.
98
+ // / @note Returns an empty vector if any component in the path was non-unique or not found. Otherwise, all declarations along the path are returned.
99
+ std::vector<Declaration const *> pathFromCurrentScopeWithAllDeclarations (std::vector<ASTString> const & _path) const ;
96
100
97
101
// / Generate and store warnings about declarations with the same name.
98
102
void warnHomonymDeclarations () const ;
Original file line number Diff line number Diff line change @@ -173,14 +173,15 @@ void ReferencesResolver::endVisit(ModifierDefinition const&)
173
173
174
174
void ReferencesResolver::endVisit (IdentifierPath const & _path)
175
175
{
176
- Declaration const * declaration = m_resolver.pathFromCurrentScope (_path.path ());
177
- if (!declaration )
176
+ std::vector< Declaration const *> declarations = m_resolver.pathFromCurrentScopeWithAllDeclarations (_path.path ());
177
+ if (declarations. empty () )
178
178
{
179
179
m_errorReporter.fatalDeclarationError (7920_error, _path.location (), " Identifier not found or not unique." );
180
180
return ;
181
181
}
182
182
183
- _path.annotation ().referencedDeclaration = declaration;
183
+ _path.annotation ().referencedDeclaration = declarations.back ();
184
+ _path.annotation ().pathDeclarations = std::move (declarations);
184
185
}
185
186
186
187
bool ReferencesResolver::visit (InlineAssembly const & _inlineAssembly)
Original file line number Diff line number Diff line change @@ -256,6 +256,9 @@ struct IdentifierPathAnnotation: ASTAnnotation
256
256
Declaration const * referencedDeclaration = nullptr ;
257
257
// / What kind of lookup needs to be done (static, virtual, super) find the declaration.
258
258
util::SetOnce<VirtualLookup> requiredLookup;
259
+
260
+ // / Declaration of each path element.
261
+ std::vector<Declaration const *> pathDeclarations;
259
262
};
260
263
261
264
struct ExpressionAnnotation : ASTAnnotation
You can’t perform that action at this time.
0 commit comments