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