@@ -962,7 +962,18 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
962962 bool startEntityDecl (ValueDecl *D);
963963
964964 bool reportRelatedRef (ValueDecl *D, SourceLoc Loc, bool isImplicit, SymbolRoleSet Relations, Decl *Related);
965- bool reportRelatedTypeRef (const TypeLoc &Ty, SymbolRoleSet Relations, Decl *Related);
965+
966+ // / Report references for dependent types
967+ // /
968+ // / NOTE: If the dependent type is a typealias, report the underlying types as well.
969+ // /
970+ // / \param Ty The type being referenced.
971+ // / \param Relations The relationship between the referenced type and the passed Decl.
972+ // / \param Related The Decl that is referencing the type.
973+ // / \param isImplicit Whether the reference is implicit, such as for a typealias' underlying type.
974+ // / \param Loc The location of the reference, otherwise the location of the TypeLoc is used.
975+ bool reportRelatedTypeRef (const TypeLoc &Ty, SymbolRoleSet Relations, Decl *Related,
976+ bool isImplicit=false , SourceLoc Loc={});
966977 bool reportInheritedTypeRefs (
967978 ArrayRef<InheritedEntry> Inherited, Decl *Inheritee);
968979
@@ -1377,20 +1388,37 @@ bool IndexSwiftASTWalker::reportInheritedTypeRefs(ArrayRef<InheritedEntry> Inher
13771388 return true ;
13781389}
13791390
1380- bool IndexSwiftASTWalker::reportRelatedTypeRef (const TypeLoc &Ty, SymbolRoleSet Relations, Decl *Related) {
1381- if (auto *declRefTR = dyn_cast_or_null<DeclRefTypeRepr>(Ty.getTypeRepr ())) {
1382- SourceLoc IdLoc = declRefTR->getLoc ();
1391+ bool IndexSwiftASTWalker::reportRelatedTypeRef (const TypeLoc &Ty, SymbolRoleSet Relations,
1392+ Decl *Related, bool Implicit, SourceLoc Loc) {
1393+ if (auto *composite = llvm::dyn_cast_or_null<CompositionTypeRepr>(Ty.getTypeRepr ())) {
1394+ SourceLoc IdLoc = Loc.isValid () ? Loc : composite->getSourceLoc ();
1395+ for (auto *Type : composite->getTypes ()) {
1396+ if (!reportRelatedTypeRef (Type, Relations, Related, /* isImplicit=*/ Implicit, IdLoc))
1397+ return false ;
1398+ }
1399+
1400+ return true ;
1401+ } else if (auto *declRefTR = dyn_cast_or_null<DeclRefTypeRepr>(Ty.getTypeRepr ())) {
1402+ SourceLoc IdLoc = Loc.isValid () ? Loc : declRefTR->getLoc ();
13831403 NominalTypeDecl *NTD = nullptr ;
1384- bool isImplicit = false ;
1404+ bool isImplicit = Implicit ;
13851405 if (auto *VD = declRefTR->getBoundDecl ()) {
13861406 if (auto *TAD = dyn_cast<TypeAliasDecl>(VD)) {
13871407 IndexSymbol Info;
1408+ if (isImplicit)
1409+ Info.roles |= (unsigned )SymbolRole::Implicit;
13881410 if (!reportRef (TAD, IdLoc, Info, None))
13891411 return false ;
13901412 if (auto Ty = TAD->getUnderlyingType ()) {
13911413 NTD = Ty->getAnyNominal ();
13921414 isImplicit = true ;
13931415 }
1416+
1417+ if (isa_and_nonnull<CompositionTypeRepr>(TAD->getUnderlyingTypeRepr ())) {
1418+ TypeLoc TL (TAD->getUnderlyingTypeRepr (), TAD->getUnderlyingType ());
1419+ if (!reportRelatedTypeRef (TL, Relations, Related, /* isImplicit=*/ true , IdLoc))
1420+ return false ;
1421+ }
13941422 } else {
13951423 NTD = dyn_cast<NominalTypeDecl>(VD);
13961424 }
0 commit comments