@@ -121,7 +121,7 @@ class NodeFinderExprResult : public NodeFinderResult {
121121// / Walks the AST, looking for a node at \c LocToResolve. While walking the
122122// / AST, also gathers information about shorthand shadows.
123123class NodeFinder : ASTWalker {
124- SourceFile &SrcFile ;
124+ DeclContext &DC ;
125125 SourceLoc LocToResolve;
126126
127127 // / As we are walking the tree, this variable is updated to the last seen
@@ -139,11 +139,10 @@ class NodeFinder : ASTWalker {
139139 llvm::DenseMap<ValueDecl *, ValueDecl *> ShorthandShadowedDecls;
140140
141141public:
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}) {}
145144
146- void resolve () { SrcFile. walk (*this ); }
145+ void resolve () { DC. walkContext (*this ); }
147146
148147 std::unique_ptr<NodeFinderResult> takeResult () { return std::move (Result); }
149148
@@ -161,9 +160,7 @@ class NodeFinder : ASTWalker {
161160 }
162161
163162private:
164- SourceManager &getSourceMgr () const {
165- return SrcFile.getASTContext ().SourceMgr ;
166- }
163+ SourceManager &getSourceMgr () const { return DC.getASTContext ().SourceMgr ; }
167164
168165 // / The decl context that is currently being walked.
169166 DeclContext *getCurrentDeclContext () { return DeclContextStack.back (); }
@@ -232,7 +229,8 @@ class NodeFinder : ASTWalker {
232229 switch (E->getKind ()) {
233230 case ExprKind::DeclRef:
234231 case ExprKind::UnresolvedDot:
235- case ExprKind::UnresolvedDeclRef: {
232+ case ExprKind::UnresolvedDeclRef:
233+ case ExprKind::OverloadedDeclRef: {
236234 assert (Result == nullptr );
237235 Result =
238236 std::make_unique<NodeFinderExprResult>(E, getCurrentDeclContext ());
@@ -280,13 +278,33 @@ class CursorInfoTypeCheckSolutionCallback : public TypeCheckCompletionCallback {
280278 };
281279
282280private:
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;
285289
286290 SmallVector<CursorInfoDeclReference, 1 > Results;
287291
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+
288302 void sawSolutionImpl (const Solution &S) override {
289303 auto &CS = S.getConstraintSystem ();
304+ auto ResolveExpr = getExprToResolve ();
305+ if (!ResolveExpr) {
306+ return ;
307+ }
290308
291309 auto Locator = CS.getConstraintLocator (ResolveExpr);
292310 auto CalleeLocator = S.getCalleeLocator (Locator);
@@ -310,8 +328,8 @@ class CursorInfoTypeCheckSolutionCallback : public TypeCheckCompletionCallback {
310328 }
311329
312330public:
313- CursorInfoTypeCheckSolutionCallback (Expr *ResolveExpr )
314- : ResolveExpr(ResolveExpr ) {}
331+ CursorInfoTypeCheckSolutionCallback (DeclContext &DC, SourceLoc ResolveLoc )
332+ : DC(DC), ResolveLoc(ResolveLoc ) {}
315333
316334 ArrayRef<CursorInfoDeclReference> getResults () const { return Results; }
317335};
@@ -332,7 +350,7 @@ class CursorInfoDoneParsingCallback : public IDEInspectionCallbacks {
332350 getDeclResult (NodeFinderDeclResult *DeclResult, SourceFile *SrcFile,
333351 NodeFinder &Finder) const {
334352 typeCheckDeclAndParentClosures (DeclResult->getDecl ());
335- return new ResolvedValueRefCursorInfo (
353+ auto CursorInfo = new ResolvedValueRefCursorInfo (
336354 SrcFile, RequestedLoc, DeclResult->getDecl (),
337355 /* CtorTyRef=*/ nullptr ,
338356 /* ExtTyRef=*/ nullptr , /* IsRef=*/ false , /* Ty=*/ Type (),
@@ -352,7 +370,7 @@ class CursorInfoDoneParsingCallback : public IDEInspectionCallbacks {
352370 DeclContext *DC = ExprResult->getDeclContext ();
353371
354372 // Type check the statemnt containing E and listen for solutions.
355- CursorInfoTypeCheckSolutionCallback Callback (E );
373+ CursorInfoTypeCheckSolutionCallback Callback (*DC, RequestedLoc );
356374 llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector (
357375 DC->getASTContext ().SolutionCallback , &Callback);
358376 typeCheckASTNodeAtLoc (TypeCheckASTNodeAtLocContext::declContext (DC),
0 commit comments