Skip to content

Commit 4bd5e11

Browse files
authored
Merge pull request #7916 from akyrtzi/index-typelias-as-base
2 parents 50fb3b6 + c5456e3 commit 4bd5e11

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

lib/Index/Index.cpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
355355
bool startEntity(Decl *D, IndexSymbol &Info);
356356
bool startEntityDecl(ValueDecl *D);
357357

358-
bool reportRelatedRef(ValueDecl *D, SourceLoc Loc, SymbolRoleSet Relations, Decl *Related);
358+
bool reportRelatedRef(ValueDecl *D, SourceLoc Loc, bool isImplicit, SymbolRoleSet Relations, Decl *Related);
359359
bool reportRelatedTypeRef(const TypeLoc &Ty, SymbolRoleSet Relations, Decl *Related);
360360
bool reportInheritedTypeRefs(ArrayRef<TypeLoc> Inherited, Decl *Inheritee);
361361
NominalTypeDecl *getTypeLocAsNominalTypeDecl(const TypeLoc &Ty);
@@ -624,13 +624,16 @@ bool IndexSwiftASTWalker::startEntityDecl(ValueDecl *D) {
624624
return startEntity(D, Info);
625625
}
626626

627-
bool IndexSwiftASTWalker::reportRelatedRef(ValueDecl *D, SourceLoc Loc, SymbolRoleSet Relations, Decl *Related) {
627+
bool IndexSwiftASTWalker::reportRelatedRef(ValueDecl *D, SourceLoc Loc, bool isImplicit,
628+
SymbolRoleSet Relations, Decl *Related) {
628629
if (!shouldIndex(D))
629630
return true;
630631

631632
IndexSymbol Info;
632633
if (addRelation(Info, Relations, Related))
633634
return true;
635+
if (isImplicit)
636+
Info.roles |= (unsigned)SymbolRole::Implicit;
634637

635638
// don't report this ref again when visitDeclReference reports it
636639
repressRefAtLoc(Loc);
@@ -655,17 +658,32 @@ bool IndexSwiftASTWalker::reportRelatedTypeRef(const TypeLoc &Ty, SymbolRoleSet
655658

656659
if (IdentTypeRepr *T = dyn_cast_or_null<IdentTypeRepr>(Ty.getTypeRepr())) {
657660
auto Comps = T->getComponentRange();
658-
if (auto NTD =
659-
dyn_cast_or_null<NominalTypeDecl>(Comps.back()->getBoundDecl())) {
660-
if (!reportRelatedRef(NTD, Comps.back()->getIdLoc(), Relations, Related))
661+
SourceLoc IdLoc = Comps.back()->getIdLoc();
662+
NominalTypeDecl *NTD = nullptr;
663+
bool isImplicit = false;
664+
if (auto *VD = Comps.back()->getBoundDecl()) {
665+
if (auto *TAD = dyn_cast<TypeAliasDecl>(VD)) {
666+
IndexSymbol Info;
667+
if (!reportRef(TAD, IdLoc, Info))
668+
return false;
669+
if (auto Ty = TAD->getUnderlyingTypeLoc().getType()) {
670+
NTD = Ty->getAnyNominal();
671+
isImplicit = true;
672+
}
673+
} else {
674+
NTD = dyn_cast<NominalTypeDecl>(VD);
675+
}
676+
}
677+
if (NTD) {
678+
if (!reportRelatedRef(NTD, IdLoc, isImplicit, Relations, Related))
661679
return false;
662680
}
663681
return true;
664682
}
665683

666684
if (Ty.getType()) {
667685
if (auto nominal = Ty.getType()->getAnyNominal())
668-
if (!reportRelatedRef(nominal, Ty.getLoc(), Relations, Related))
686+
if (!reportRelatedRef(nominal, Ty.getLoc(), /*isImplicit=*/false, Relations, Related))
669687
return false;
670688
}
671689
return true;
@@ -752,8 +770,8 @@ bool IndexSwiftASTWalker::reportExtension(ExtensionDecl *D) {
752770
if (!startEntity(D, Info))
753771
return false;
754772

755-
if (!reportRelatedRef(NTD, Loc, (SymbolRoleSet)SymbolRole::RelationExtendedBy,
756-
D))
773+
if (!reportRelatedRef(NTD, Loc, /*isImplicit=*/false,
774+
(SymbolRoleSet)SymbolRole::RelationExtendedBy, D))
757775
return false;
758776
if (!reportInheritedTypeRefs(D->getInherited(), D))
759777
return false;

test/Index/kinds.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,13 @@ class AttrAnnots {
214214
@GKInspectable var gkString = "gk"
215215
// CHECK: [[@LINE-1]]:22 | instance-property(GKI)/Swift | gkString |
216216
}
217+
218+
// CHECK: [[@LINE+1]]:7 | class/Swift | C1 | [[C1_USR:.*]] | Def | rel: 0
219+
class C1 {}
220+
// CHECK: [[@LINE+1]]:11 | type-alias/Swift | C1Alias | [[C1Alias_USR:.*]] | Def | rel: 0
221+
typealias C1Alias = C1
222+
// CHECK: [[@LINE+4]]:7 | class/Swift | SubC1 | [[SubC1_USR:.*]] | Def | rel: 0
223+
// CHECK: [[@LINE+3]]:15 | type-alias/Swift | C1Alias | [[C1Alias_USR]] | Ref | rel: 0
224+
// CHECK: [[@LINE+2]]:15 | class/Swift | C1 | [[C1_USR]] | Ref,Impl,RelBase | rel: 1
225+
// CHECK-NEXT: RelBase | SubC1 | [[SubC1_USR]]
226+
class SubC1 : C1Alias {}

0 commit comments

Comments
 (0)