@@ -225,7 +225,8 @@ class NodeFinder : ASTWalker {
225
225
switch (E->getKind ()) {
226
226
case ExprKind::DeclRef:
227
227
case ExprKind::UnresolvedDot:
228
- case ExprKind::UnresolvedDeclRef: {
228
+ case ExprKind::UnresolvedDeclRef:
229
+ case ExprKind::OverloadedDeclRef: {
229
230
assert (Result == nullptr );
230
231
Result =
231
232
std::make_unique<NodeFinderExprResult>(E, getCurrentDeclContext ());
@@ -273,13 +274,33 @@ class CursorInfoTypeCheckSolutionCallback : public TypeCheckCompletionCallback {
273
274
};
274
275
275
276
private:
276
- // / The expression for which we want to provide cursor info results.
277
- Expr *ResolveExpr;
277
+ // / The source file and location to resolve.
278
+ // / Note that we cannot store the expression to resolve directly because an
279
+ // / \c UnresolvedDeclRefExpr might be replaced by an \c OverloadedDeclRefExpr
280
+ // / and thus the constraint system solution doesn't know about the
281
+ // / \c UnresolvedDeclRefExpr. Instead, we find the expression to resolve in
282
+ // / the source file again after expression pre-check has run.
283
+ SourceFile &SrcFile;
284
+ SourceLoc ResolveLoc;
278
285
279
286
SmallVector<CursorInfoDeclReference, 1 > Results;
280
287
288
+ Expr *getExprToResolve () {
289
+ NodeFinder Finder (SrcFile, ResolveLoc);
290
+ Finder.resolve ();
291
+ auto Result = Finder.takeResult ();
292
+ if (!Result || Result->getKind () != NodeFinderResultKind::Expr) {
293
+ return nullptr ;
294
+ }
295
+ return cast<NodeFinderExprResult>(Result.get ())->getExpr ();
296
+ }
297
+
281
298
void sawSolutionImpl (const Solution &S) override {
282
299
auto &CS = S.getConstraintSystem ();
300
+ auto ResolveExpr = getExprToResolve ();
301
+ if (!ResolveExpr) {
302
+ return ;
303
+ }
283
304
284
305
auto Locator = CS.getConstraintLocator (ResolveExpr);
285
306
auto CalleeLocator = S.getCalleeLocator (Locator);
@@ -303,8 +324,8 @@ class CursorInfoTypeCheckSolutionCallback : public TypeCheckCompletionCallback {
303
324
}
304
325
305
326
public:
306
- CursorInfoTypeCheckSolutionCallback (Expr *ResolveExpr )
307
- : ResolveExpr(ResolveExpr ) {}
327
+ CursorInfoTypeCheckSolutionCallback (SourceFile &SrcFile, SourceLoc ResolveLoc )
328
+ : SrcFile(SrcFile), ResolveLoc(ResolveLoc ) {}
308
329
309
330
ArrayRef<CursorInfoDeclReference> getResults () const { return Results; }
310
331
};
@@ -325,7 +346,7 @@ class CursorInfoDoneParsingCallback : public IDEInspectionCallbacks {
325
346
getDeclResult (NodeFinderDeclResult *DeclResult, SourceFile *SrcFile,
326
347
NodeFinder &Finder) const {
327
348
typeCheckDeclAndParentClosures (DeclResult->getDecl ());
328
- return new ResolvedValueRefCursorInfo (
349
+ auto CursorInfo = new ResolvedValueRefCursorInfo (
329
350
SrcFile, RequestedLoc, DeclResult->getDecl (),
330
351
/* CtorTyRef=*/ nullptr ,
331
352
/* ExtTyRef=*/ nullptr , /* IsRef=*/ false , /* Ty=*/ Type (),
@@ -345,7 +366,7 @@ class CursorInfoDoneParsingCallback : public IDEInspectionCallbacks {
345
366
DeclContext *DC = ExprResult->getDeclContext ();
346
367
347
368
// Type check the statemnt containing E and listen for solutions.
348
- CursorInfoTypeCheckSolutionCallback Callback (E );
369
+ CursorInfoTypeCheckSolutionCallback Callback (*SrcFile, RequestedLoc );
349
370
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector (
350
371
DC->getASTContext ().SolutionCallback , &Callback);
351
372
typeCheckASTNodeAtLoc (TypeCheckASTNodeAtLocContext::declContext (DC),
0 commit comments