@@ -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
NominalTypeDecl *getTypeLocAsNominalTypeDecl (const TypeLoc &Ty);
@@ -1378,20 +1389,37 @@ bool IndexSwiftASTWalker::reportInheritedTypeRefs(ArrayRef<InheritedEntry> Inher
1378
1389
return true ;
1379
1390
}
1380
1391
1381
- bool IndexSwiftASTWalker::reportRelatedTypeRef (const TypeLoc &Ty, SymbolRoleSet Relations, Decl *Related) {
1382
- if (auto *declRefTR = dyn_cast_or_null<DeclRefTypeRepr>(Ty.getTypeRepr ())) {
1383
- SourceLoc IdLoc = declRefTR->getLoc ();
1392
+ bool IndexSwiftASTWalker::reportRelatedTypeRef (const TypeLoc &Ty, SymbolRoleSet Relations,
1393
+ Decl *Related, bool Implicit, SourceLoc Loc) {
1394
+ if (auto *composite = llvm::dyn_cast_or_null<CompositionTypeRepr>(Ty.getTypeRepr ())) {
1395
+ SourceLoc IdLoc = Loc.isValid () ? Loc : composite->getSourceLoc ();
1396
+ for (auto *Type : composite->getTypes ()) {
1397
+ if (!reportRelatedTypeRef (Type, Relations, Related, /* isImplicit=*/ Implicit, IdLoc))
1398
+ return false ;
1399
+ }
1400
+
1401
+ return true ;
1402
+ } else if (auto *declRefTR = dyn_cast_or_null<DeclRefTypeRepr>(Ty.getTypeRepr ())) {
1403
+ SourceLoc IdLoc = Loc.isValid () ? Loc : declRefTR->getLoc ();
1384
1404
NominalTypeDecl *NTD = nullptr ;
1385
- bool isImplicit = false ;
1405
+ bool isImplicit = Implicit ;
1386
1406
if (auto *VD = declRefTR->getBoundDecl ()) {
1387
1407
if (auto *TAD = dyn_cast<TypeAliasDecl>(VD)) {
1388
1408
IndexSymbol Info;
1409
+ if (isImplicit)
1410
+ Info.roles |= (unsigned )SymbolRole::Implicit;
1389
1411
if (!reportRef (TAD, IdLoc, Info, None))
1390
1412
return false ;
1391
1413
if (auto Ty = TAD->getUnderlyingType ()) {
1392
1414
NTD = Ty->getAnyNominal ();
1393
1415
isImplicit = true ;
1394
1416
}
1417
+
1418
+ if (isa_and_nonnull<CompositionTypeRepr>(TAD->getUnderlyingTypeRepr ())) {
1419
+ TypeLoc TL (TAD->getUnderlyingTypeRepr (), TAD->getUnderlyingType ());
1420
+ if (!reportRelatedTypeRef (TL, Relations, Related, /* isImplicit=*/ true , IdLoc))
1421
+ return false ;
1422
+ }
1395
1423
} else {
1396
1424
NTD = dyn_cast<NominalTypeDecl>(VD);
1397
1425
}
0 commit comments