Skip to content

Commit 7415cb8

Browse files
authored
Merge pull request #62455 from bnbarham/index-handle-implicit-conversions
[Index] Use `ide::getReferencedDecl` instead of custom `extractDecl`
2 parents deae449 + 7fb229a commit 7415cb8

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
@@ -800,7 +788,11 @@ passReference(ValueDecl *D, Type Ty, SourceLoc BaseNameLoc, SourceRange Range,
800788
if (!CtorRefs.empty() && BaseNameLoc.isValid()) {
801789
Expr *Fn = CtorRefs.back()->getFn();
802790
if (Fn->getLoc() == BaseNameLoc) {
803-
D = extractDecl(Fn);
791+
D = ide::getReferencedDecl(Fn).second.getDecl();
792+
if (D == nullptr) {
793+
assert(false && "Unhandled constructor reference");
794+
return true;
795+
}
804796
CtorTyRef = TD;
805797
}
806798
}
@@ -815,12 +807,6 @@ passReference(ValueDecl *D, Type Ty, SourceLoc BaseNameLoc, SourceRange Range,
815807
}
816808
}
817809

818-
if (D == nullptr) {
819-
// FIXME: When does this happen?
820-
assert(false && "unhandled reference");
821-
return true;
822-
}
823-
824810
CharSourceRange CharRange =
825811
Lexer::getCharSourceRangeFromSourceRange(D->getASTContext().SourceMgr,
826812
Range);
@@ -839,7 +825,7 @@ bool SemaAnnotator::passReference(ModuleEntity Mod,
839825
}
840826

841827
bool SemaAnnotator::passCallArgNames(Expr *Fn, ArgumentList *ArgList) {
842-
ValueDecl *D = extractDecl(Fn);
828+
ValueDecl *D = ide::getReferencedDecl(Fn).second.getDecl();
843829
if (!D)
844830
return true; // continue.
845831

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)