@@ -121,7 +121,7 @@ class NodeFinderExprResult : public NodeFinderResult {
121
121
// / Walks the AST, looking for a node at \c LocToResolve. While walking the
122
122
// / AST, also gathers information about shorthand shadows.
123
123
class NodeFinder : ASTWalker {
124
- SourceFile &SrcFile ;
124
+ DeclContext &DC ;
125
125
SourceLoc LocToResolve;
126
126
127
127
// / As we are walking the tree, this variable is updated to the last seen
@@ -139,11 +139,10 @@ class NodeFinder : ASTWalker {
139
139
llvm::DenseMap<ValueDecl *, ValueDecl *> ShorthandShadowedDecls;
140
140
141
141
public:
142
- NodeFinder (SourceFile &SrcFile, SourceLoc LocToResolve)
143
- : SrcFile(SrcFile), LocToResolve(LocToResolve),
144
- DeclContextStack ({&SrcFile}) {}
142
+ NodeFinder (DeclContext &DC, SourceLoc LocToResolve)
143
+ : DC(DC), LocToResolve(LocToResolve), DeclContextStack({&DC}) {}
145
144
146
- void resolve () { SrcFile. walk (*this ); }
145
+ void resolve () { DC. walkContext (*this ); }
147
146
148
147
std::unique_ptr<NodeFinderResult> takeResult () { return std::move (Result); }
149
148
@@ -161,9 +160,7 @@ class NodeFinder : ASTWalker {
161
160
}
162
161
163
162
private:
164
- SourceManager &getSourceMgr () const {
165
- return SrcFile.getASTContext ().SourceMgr ;
166
- }
163
+ SourceManager &getSourceMgr () const { return DC.getASTContext ().SourceMgr ; }
167
164
168
165
// / The decl context that is currently being walked.
169
166
DeclContext *getCurrentDeclContext () { return DeclContextStack.back (); }
@@ -232,7 +229,8 @@ class NodeFinder : ASTWalker {
232
229
switch (E->getKind ()) {
233
230
case ExprKind::DeclRef:
234
231
case ExprKind::UnresolvedDot:
235
- case ExprKind::UnresolvedDeclRef: {
232
+ case ExprKind::UnresolvedDeclRef:
233
+ case ExprKind::OverloadedDeclRef: {
236
234
assert (Result == nullptr );
237
235
Result =
238
236
std::make_unique<NodeFinderExprResult>(E, getCurrentDeclContext ());
@@ -280,13 +278,33 @@ class CursorInfoTypeCheckSolutionCallback : public TypeCheckCompletionCallback {
280
278
};
281
279
282
280
private:
283
- // / The expression for which we want to provide cursor info results.
284
- Expr *ResolveExpr;
281
+ // / The location to resolve and the \c DeclContext to resolve it in.
282
+ // / Note that we cannot store the expression to resolve directly because an
283
+ // / \c UnresolvedDeclRefExpr might be replaced by an \c OverloadedDeclRefExpr
284
+ // / and thus the constraint system solution doesn't know about the
285
+ // / \c UnresolvedDeclRefExpr. Instead, we find the expression to resolve in
286
+ // / the source file again after expression pre-check has run.
287
+ DeclContext &DC;
288
+ SourceLoc ResolveLoc;
285
289
286
290
SmallVector<CursorInfoDeclReference, 1 > Results;
287
291
292
+ Expr *getExprToResolve () {
293
+ NodeFinder Finder (DC, ResolveLoc);
294
+ Finder.resolve ();
295
+ auto Result = Finder.takeResult ();
296
+ if (!Result || Result->getKind () != NodeFinderResultKind::Expr) {
297
+ return nullptr ;
298
+ }
299
+ return cast<NodeFinderExprResult>(Result.get ())->getExpr ();
300
+ }
301
+
288
302
void sawSolutionImpl (const Solution &S) override {
289
303
auto &CS = S.getConstraintSystem ();
304
+ auto ResolveExpr = getExprToResolve ();
305
+ if (!ResolveExpr) {
306
+ return ;
307
+ }
290
308
291
309
auto Locator = CS.getConstraintLocator (ResolveExpr);
292
310
auto CalleeLocator = S.getCalleeLocator (Locator);
@@ -310,8 +328,8 @@ class CursorInfoTypeCheckSolutionCallback : public TypeCheckCompletionCallback {
310
328
}
311
329
312
330
public:
313
- CursorInfoTypeCheckSolutionCallback (Expr *ResolveExpr )
314
- : ResolveExpr(ResolveExpr ) {}
331
+ CursorInfoTypeCheckSolutionCallback (DeclContext &DC, SourceLoc ResolveLoc )
332
+ : DC(DC), ResolveLoc(ResolveLoc ) {}
315
333
316
334
ArrayRef<CursorInfoDeclReference> getResults () const { return Results; }
317
335
};
@@ -332,7 +350,7 @@ class CursorInfoDoneParsingCallback : public IDEInspectionCallbacks {
332
350
getDeclResult (NodeFinderDeclResult *DeclResult, SourceFile *SrcFile,
333
351
NodeFinder &Finder) const {
334
352
typeCheckDeclAndParentClosures (DeclResult->getDecl ());
335
- return new ResolvedValueRefCursorInfo (
353
+ auto CursorInfo = new ResolvedValueRefCursorInfo (
336
354
SrcFile, RequestedLoc, DeclResult->getDecl (),
337
355
/* CtorTyRef=*/ nullptr ,
338
356
/* ExtTyRef=*/ nullptr , /* IsRef=*/ false , /* Ty=*/ Type (),
@@ -352,7 +370,7 @@ class CursorInfoDoneParsingCallback : public IDEInspectionCallbacks {
352
370
DeclContext *DC = ExprResult->getDeclContext ();
353
371
354
372
// Type check the statemnt containing E and listen for solutions.
355
- CursorInfoTypeCheckSolutionCallback Callback (E );
373
+ CursorInfoTypeCheckSolutionCallback Callback (*DC, RequestedLoc );
356
374
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector (
357
375
DC->getASTContext ().SolutionCallback , &Callback);
358
376
typeCheckASTNodeAtLoc (TypeCheckASTNodeAtLocContext::declContext (DC),
0 commit comments