Skip to content

Commit 9773bdd

Browse files
committed
Fix missing indexing data when using Self initializer
Fixes: #64686
1 parent bfe975d commit 9773bdd

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

Diff for: lib/IDE/SourceEntityWalker.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,17 @@ ASTWalker::PreWalkAction SemaAnnotator::walkToTypeReprPre(TypeRepr *T) {
633633
ReferenceMetaData(SemaReferenceKind::TypeRef, None));
634634
return Action::StopIf(!Continue);
635635
}
636+
} else if (auto FT = dyn_cast<FixedTypeRepr>(T)) {
637+
ValueDecl *VD = FT->getType()->getAnyGeneric();
638+
if (auto DT = FT->getType()->getAs<DynamicSelfType>())
639+
VD = DT->getSelfType()->getAnyGeneric();
640+
641+
if (VD) {
642+
auto Data = ReferenceMetaData(SemaReferenceKind::DynamicMemberRef, None, /*isImplicit=*/true);
643+
auto Continue = passReference(VD, FT->getType(), FT->getLoc(),
644+
FT->getSourceRange(), Data);
645+
return Action::StopIf(!Continue);
646+
}
636647
}
637648

638649
return Action::Continue();

Diff for: lib/IDE/Utils.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,10 @@ bool swift::ide::isBeingCalled(ArrayRef<Expr *> ExprStack) {
853853
if (CRCE->getBase() == Target)
854854
return true;
855855
}
856+
if (auto *CRCE = dyn_cast<ConstructorRefCallExpr>(AE->getFn()))
857+
if (auto *MCE = dyn_cast<MetatypeConversionExpr>(CRCE->getBase()))
858+
if (MCE->getSubExpr() == Target)
859+
return true;
856860
if (isa<SelfApplyExpr>(AE))
857861
continue;
858862
if (getReferencedDecl(AE->getFn()).second == UnderlyingDecl)

Diff for: lib/Index/Index.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,8 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
856856

857857
if (Data.isImplicit)
858858
Info.roles |= (unsigned)SymbolRole::Implicit;
859+
if (Data.Kind == SemaReferenceKind::DynamicMemberRef)
860+
Info.roles |= (unsigned)SymbolRole::Dynamic;
859861

860862
if (CtorTyRef)
861863
if (!reportRef(CtorTyRef, Loc, Info, Data.AccKind))

Diff for: test/Index/index_self.swift

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %target-swift-ide-test -print-indexed-symbols -source-filename %s | %FileCheck %s
2+
3+
struct Foo { // CHECK: [[@LINE]]:8 | struct/Swift | Foo | [[Foo_USR:.*]] | Def | rel: 0
4+
init() {} // CHECK: [[@LINE]]:3 | constructor/Swift | init() | [[Foo_init_USR:.*]] | Def,RelChild | rel: 1
5+
6+
static func bar() -> Self {
7+
.init() // CHECK: [[@LINE]]:6 | constructor/Swift | init() | [[Foo_init_USR]] | Ref,Call,RelCall,RelCont | rel: 1
8+
}
9+
10+
static func baz() -> Self {
11+
Self()
12+
// CHECK: [[@LINE-1]]:5 | struct/Swift | Foo | [[Foo_USR]] | Ref,Dyn,Impl,RelCont | rel: 1
13+
// CHECK: [[@LINE-2]]:5 | constructor/Swift | init() | [[Foo_init_USR]] | Ref,Call,Dyn,Impl,RelCall,RelCont | rel: 1
14+
}
15+
}
16+
17+
class Bar { // CHECK: [[@LINE]]:7 | class/Swift | Bar | [[Bar_USR:.*]] | Def | rel: 0
18+
required init() {} // CHECK: [[@LINE]]:12 | constructor/Swift | init() | [[Bar_init_USR:.*]] | Def,RelChild | rel: 1
19+
20+
static func foo() -> Self {
21+
.init() // CHECK: [[@LINE]]:6 | constructor/Swift | init() | [[Bar_init_USR]] | Ref,Call,RelCall,RelCont | rel: 1
22+
}
23+
24+
static func baz() -> Self {
25+
Self()
26+
// CHECK: [[@LINE-1]]:5 | class/Swift | Bar | [[Bar_USR]] | Ref,Dyn,Impl,RelCont | rel: 1
27+
// CHECK: [[@LINE-2]]:5 | constructor/Swift | init() | [[Bar_init_USR]] | Ref,Call,Dyn,Impl,RelCall,RelCont | rel: 1
28+
}
29+
}
30+
31+
class Baz: Bar {}

0 commit comments

Comments
 (0)