Skip to content

Commit 7fb229a

Browse files
committed
[Index] Use ide::getReferencedDecl instead of custom extractDecl
`passReference` was failing to find the underlying declaration for a constructor reference. In this case it was for a `FunctionConversionExpr`, but there's likely others. Use `ide::getReferencedDecl` instead. Resolves rdar://102563191.
1 parent 571671f commit 7fb229a

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

lib/IDE/SourceEntityWalker.cpp

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "swift/IDE/SourceEntityWalker.h"
1413
#include "swift/AST/ASTContext.h"
1514
#include "swift/AST/ASTWalker.h"
1615
#include "swift/AST/Decl.h"
@@ -26,6 +25,8 @@
2625
#include "swift/Basic/SourceManager.h"
2726
#include "swift/Parse/Lexer.h"
2827
#include "clang/Basic/Module.h"
28+
#include "swift/IDE/SourceEntityWalker.h"
29+
#include "swift/IDE/Utils.h"
2930

3031
using namespace swift;
3132

@@ -93,19 +94,6 @@ class SemaAnnotator : public ASTWalker {
9394
bool passCallArgNames(Expr *Fn, ArgumentList *ArgList);
9495

9596
bool shouldIgnore(Decl *D);
96-
97-
ValueDecl *extractDecl(Expr *Fn) const {
98-
Fn = Fn->getSemanticsProvidingExpr();
99-
if (auto *DRE = dyn_cast<DeclRefExpr>(Fn))
100-
return DRE->getDecl();
101-
if (auto ApplyE = dyn_cast<ApplyExpr>(Fn))
102-
return extractDecl(ApplyE->getFn());
103-
if (auto *ACE = dyn_cast<AutoClosureExpr>(Fn)) {
104-
if (auto *Unwrapped = ACE->getUnwrappedCurryThunkExpr())
105-
return extractDecl(Unwrapped);
106-
}
107-
return nullptr;
108-
}
10997
};
11098

11199
} // end anonymous namespace
@@ -803,7 +791,11 @@ passReference(ValueDecl *D, Type Ty, SourceLoc BaseNameLoc, SourceRange Range,
803791
if (!CtorRefs.empty() && BaseNameLoc.isValid()) {
804792
Expr *Fn = CtorRefs.back()->getFn();
805793
if (Fn->getLoc() == BaseNameLoc) {
806-
D = extractDecl(Fn);
794+
D = ide::getReferencedDecl(Fn).second.getDecl();
795+
if (D == nullptr) {
796+
assert(false && "Unhandled constructor reference");
797+
return true;
798+
}
807799
CtorTyRef = TD;
808800
}
809801
}
@@ -818,12 +810,6 @@ passReference(ValueDecl *D, Type Ty, SourceLoc BaseNameLoc, SourceRange Range,
818810
}
819811
}
820812

821-
if (D == nullptr) {
822-
// FIXME: When does this happen?
823-
assert(false && "unhandled reference");
824-
return true;
825-
}
826-
827813
CharSourceRange CharRange =
828814
Lexer::getCharSourceRangeFromSourceRange(D->getASTContext().SourceMgr,
829815
Range);
@@ -842,7 +828,7 @@ bool SemaAnnotator::passReference(ModuleEntity Mod,
842828
}
843829

844830
bool SemaAnnotator::passCallArgNames(Expr *Fn, ArgumentList *ArgList) {
845-
ValueDecl *D = extractDecl(Fn);
831+
ValueDecl *D = ide::getReferencedDecl(Fn).second.getDecl();
846832
if (!D)
847833
return true; // continue.
848834

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// REQUIRES: objc_interop, concurrency
2+
3+
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -print-indexed-symbols -source-filename %s | %FileCheck %s
4+
5+
import AppKit
6+
7+
@MainActor
8+
class AppDelegate {
9+
let window = NSWindow()
10+
// CHECK: [[@LINE-1]]:16 | class/Swift | NSWindow | c:objc(cs)NSWindow | Ref,RelCont
11+
// CHECK: [[@LINE-2]]:16 | constructor/Swift | init() | c:objc(cs)NSObject(im)init | Ref,Call,RelCont
12+
}

0 commit comments

Comments
 (0)