Skip to content

Commit 023b0db

Browse files
committed
Fix RelBase indexing with composite types
Previously the index data differed when using `Foo, Bar` vs `Foo & Bar`. Fixes #56255
1 parent 6854bbe commit 023b0db

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/Index/Index.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,8 +1372,14 @@ bool IndexSwiftASTWalker::reportRelatedRef(ValueDecl *D, SourceLoc Loc, bool isI
13721372

13731373
bool IndexSwiftASTWalker::reportInheritedTypeRefs(ArrayRef<InheritedEntry> Inherited, Decl *Inheritee) {
13741374
for (auto Base : Inherited) {
1375-
if (!reportRelatedTypeRef(Base, (SymbolRoleSet) SymbolRole::RelationBaseOf, Inheritee))
1376-
return false;
1375+
if (auto *composite = llvm::dyn_cast_or_null<CompositionTypeRepr>(Base.getTypeRepr())) {
1376+
for (auto *type : composite->getTypes())
1377+
if (!reportRelatedTypeRef(type, (SymbolRoleSet) SymbolRole::RelationBaseOf, Inheritee))
1378+
return false;
1379+
} else {
1380+
if (!reportRelatedTypeRef(Base, (SymbolRoleSet) SymbolRole::RelationBaseOf, Inheritee))
1381+
return false;
1382+
}
13771383
}
13781384
return true;
13791385
}

test/Index/conformances.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protocol P3 {
5757
func meth2() // CHECK: [[@LINE]]:8 | instance-method/Swift | meth2() | [[P3_meth2_USR:.*]] | Def
5858
}
5959

60-
class BaseMultiConf {
60+
class BaseMultiConf { // CHECK: [[@LINE]]:7 | class/Swift | BaseMultiConf | [[BaseMultiConf_USR:.*]] | Def
6161
func meth2() {} // CHECK: [[@LINE]]:8 | instance-method/Swift | meth2() | [[BaseMultiConf_meth2_USR:.*]] | Def
6262
}
6363
extension SubMultiConf {
@@ -79,6 +79,12 @@ class SubMultiConf: BaseMultiConf,P2,P1,P3 { // CHECK: [[@LINE]]:7 | class/Swift
7979
// CHECK-NOT: [[@LINE-13]]:7 | instance-method
8080
}
8181

82+
class CompositionType: BaseMultiConf & P1 { // CHECK: [[@LINE]]:7 | class/Swift | CompositionType | [[CompositionType_USR:.*]] | Def
83+
// CHECK: [[@LINE-1]]:24 | class/Swift | BaseMultiConf | [[BaseMultiConf_USR]] | Ref,RelBase | rel: 1
84+
// CHECK: [[@LINE-2]]:40 | protocol/Swift | P1 | [[P1_USR]] | Ref,RelBase | rel: 1
85+
func foo() {}
86+
}
87+
8288
protocol InheritingP: P1 { // CHECK: [[@LINE]]:10 | protocol/Swift | InheritingP | [[InheritingP_USR:.*]] | Def
8389
func foo() // CHECK: [[@LINE]]:8 | instance-method/Swift | foo() | [[InheritingP_foo_USR:.*]] | Def,Dyn,RelChild,RelOver | rel: 2
8490
// CHECK-NEXT: RelOver | instance-method/Swift | foo() | s:14swift_ide_test2P1P3fooyyF

0 commit comments

Comments
 (0)