@@ -878,6 +878,10 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
878
878
auto AfterDollar = Loc.getAdvancedLoc (1 );
879
879
reportRef (Wrapped, AfterDollar, Info, None);
880
880
}
881
+ } else if (auto *TAD = dyn_cast<TypeAliasDecl>(D)) {
882
+ TypeLoc TL (TAD->getUnderlyingTypeRepr (), TAD->getUnderlyingType ());
883
+ if (!reportRelatedTypeRef (TL, (SymbolRoleSet)SymbolRole::Reference, D, /* isImplicit=*/ true , Loc))
884
+ return false ;
881
885
}
882
886
883
887
return true ;
@@ -962,7 +966,8 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
962
966
bool startEntityDecl (ValueDecl *D);
963
967
964
968
bool reportRelatedRef (ValueDecl *D, SourceLoc Loc, bool isImplicit, SymbolRoleSet Relations, Decl *Related);
965
- bool reportRelatedTypeRef (const TypeLoc &Ty, SymbolRoleSet Relations, Decl *Related);
969
+ bool reportRelatedTypeRef (const TypeLoc &Ty, SymbolRoleSet Relations, Decl *Related,
970
+ bool isImplicit=false , const Optional<SourceLoc> Loc=Optional<SourceLoc>());
966
971
bool reportInheritedTypeRefs (
967
972
ArrayRef<InheritedEntry> Inherited, Decl *Inheritee);
968
973
NominalTypeDecl *getTypeLocAsNominalTypeDecl (const TypeLoc &Ty);
@@ -1372,32 +1377,47 @@ bool IndexSwiftASTWalker::reportRelatedRef(ValueDecl *D, SourceLoc Loc, bool isI
1372
1377
1373
1378
bool IndexSwiftASTWalker::reportInheritedTypeRefs (ArrayRef<InheritedEntry> Inherited, Decl *Inheritee) {
1374
1379
for (auto Base : Inherited) {
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
- }
1380
+ if (!reportRelatedTypeRef (Base, (SymbolRoleSet) SymbolRole::RelationBaseOf, Inheritee))
1381
+ return false ;
1383
1382
}
1384
1383
return true ;
1385
1384
}
1386
1385
1387
- bool IndexSwiftASTWalker::reportRelatedTypeRef (const TypeLoc &Ty, SymbolRoleSet Relations, Decl *Related) {
1388
- if (auto *declRefTR = dyn_cast_or_null<DeclRefTypeRepr>(Ty.getTypeRepr ())) {
1386
+ bool IndexSwiftASTWalker::reportRelatedTypeRef (const TypeLoc &Ty, SymbolRoleSet Relations,
1387
+ Decl *Related, bool Implicit, const Optional<SourceLoc> Loc) {
1388
+ if (auto *composite = llvm::dyn_cast_or_null<CompositionTypeRepr>(Ty.getTypeRepr ())) {
1389
+ SourceLoc IdLoc = composite->getSourceLoc ();
1390
+ if (auto ParentLoc = Loc)
1391
+ IdLoc = *ParentLoc;
1392
+ for (auto *Type : composite->getTypes ())
1393
+ if (!reportRelatedTypeRef (Type, Relations, Related, /* isImplicit=*/ Implicit, IdLoc))
1394
+ return false ;
1395
+
1396
+ return true ;
1397
+ } else if (auto *declRefTR = dyn_cast_or_null<DeclRefTypeRepr>(Ty.getTypeRepr ())) {
1389
1398
SourceLoc IdLoc = declRefTR->getLoc ();
1399
+ if (auto ParentLoc = Loc)
1400
+ IdLoc = *ParentLoc;
1390
1401
NominalTypeDecl *NTD = nullptr ;
1391
- bool isImplicit = false ;
1402
+ bool isImplicit = Implicit ;
1392
1403
if (auto *VD = declRefTR->getBoundDecl ()) {
1393
1404
if (auto *TAD = dyn_cast<TypeAliasDecl>(VD)) {
1394
1405
IndexSymbol Info;
1406
+ Info.roles |= Relations;
1407
+ if (isImplicit)
1408
+ Info.roles |= (unsigned )SymbolRole::Implicit;
1395
1409
if (!reportRef (TAD, IdLoc, Info, None))
1396
1410
return false ;
1397
1411
if (auto Ty = TAD->getUnderlyingType ()) {
1398
1412
NTD = Ty->getAnyNominal ();
1399
1413
isImplicit = true ;
1400
1414
}
1415
+
1416
+ if (auto *composite = llvm::dyn_cast_or_null<CompositionTypeRepr>(TAD->getUnderlyingTypeRepr ())) {
1417
+ TypeLoc TL (TAD->getUnderlyingTypeRepr (), TAD->getUnderlyingType ());
1418
+ if (!reportRelatedTypeRef (TL, Relations, Related, /* isImplicit=*/ true , IdLoc))
1419
+ return false ;
1420
+ }
1401
1421
} else {
1402
1422
NTD = dyn_cast<NominalTypeDecl>(VD);
1403
1423
}
0 commit comments