Skip to content

Commit 89cc2ff

Browse files
committed
Fix indexing constructors with generic parameters
Previously in the case of a constructor like `A<Int>(value: 1)` `Fn->getLoc()` returned the location of `>(value: 1)` while the actual location we're looking for is correctly the start of `A<Int>(value: 1)`. This adjusts the location we're looking up to use the start location of the constructor instead. Fixes: #54532
1 parent d445a18 commit 89cc2ff

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/IDE/SourceEntityWalker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -815,9 +815,9 @@ passReference(ValueDecl *D, Type Ty, SourceLoc BaseNameLoc, SourceRange Range,
815815

816816
if (auto *TD = dyn_cast<TypeDecl>(D)) {
817817
if (!CtorRefs.empty() && BaseNameLoc.isValid()) {
818-
Expr *Fn = CtorRefs.back()->getFn();
819-
if (Fn->getLoc() == BaseNameLoc) {
820-
D = ide::getReferencedDecl(Fn).second.getDecl();
818+
ConstructorRefCallExpr *Ctor = CtorRefs.back();
819+
if (Ctor->getStartLoc() == BaseNameLoc) {
820+
D = ide::getReferencedDecl(Ctor->getFn()).second.getDecl();
821821
if (D == nullptr) {
822822
assert(false && "Unhandled constructor reference");
823823
return true;

test/Index/index_generic_params.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,17 @@ extension Wrapper2.NonGenericWrapped where Wrapper2Param: P1 {
8686
extension MyUnknownType where Wrapper2Param: P1 {
8787
func foo(x: Wrapper2Param) {}
8888
}
89+
90+
// MARK: - Test indexing a generic initializer
91+
92+
struct A<T> { // CHECK: [[@LINE]]:8 | struct/Swift | A | [[A_USR:.*]] | Def | rel: 0
93+
init(value: T) {} // CHECK: [[@LINE]]:3 | constructor/Swift | init(value:) | [[A_init_USR:.*]] | Def,RelChild | rel: 1
94+
}
95+
96+
// CHECK: [[@LINE+2]]:5 | struct/Swift | A | [[A_USR]] | Ref | rel: 0
97+
// CHECK: [[@LINE+1]]:5 | constructor/Swift | init(value:) | [[A_init_USR]] | Ref,Call | rel: 0
98+
_ = A(value: 1)
99+
// CHECK: [[@LINE+3]]:5 | struct/Swift | A | [[A_USR]] | Ref | rel: 0
100+
// CHECK: [[@LINE+2]]:5 | constructor/Swift | init(value:) | [[A_init_USR]] | Ref,Call | rel: 0
101+
// CHECK: [[@LINE+1]]:7 | struct/Swift | Int | s:Si | Ref | rel: 0
102+
_ = A<Int>(value: 1)

0 commit comments

Comments
 (0)