@@ -962,7 +962,18 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
962
962
bool startEntityDecl (ValueDecl *D);
963
963
964
964
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={});
966
977
bool reportInheritedTypeRefs (
967
978
ArrayRef<InheritedEntry> Inherited, Decl *Inheritee);
968
979
@@ -1377,20 +1388,37 @@ bool IndexSwiftASTWalker::reportInheritedTypeRefs(ArrayRef<InheritedEntry> Inher
1377
1388
return true ;
1378
1389
}
1379
1390
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 ();
1383
1403
NominalTypeDecl *NTD = nullptr ;
1384
- bool isImplicit = false ;
1404
+ bool isImplicit = Implicit ;
1385
1405
if (auto *VD = declRefTR->getBoundDecl ()) {
1386
1406
if (auto *TAD = dyn_cast<TypeAliasDecl>(VD)) {
1387
1407
IndexSymbol Info;
1408
+ if (isImplicit)
1409
+ Info.roles |= (unsigned )SymbolRole::Implicit;
1388
1410
if (!reportRef (TAD, IdLoc, Info, None))
1389
1411
return false ;
1390
1412
if (auto Ty = TAD->getUnderlyingType ()) {
1391
1413
NTD = Ty->getAnyNominal ();
1392
1414
isImplicit = true ;
1393
1415
}
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
+ }
1394
1422
} else {
1395
1423
NTD = dyn_cast<NominalTypeDecl>(VD);
1396
1424
}
0 commit comments