@@ -1755,6 +1755,41 @@ void CompletionLookup::addNominalTypeRef(const NominalTypeDecl *NTD,
1755
1755
Builder.setTypeContext (expectedTypeContext, CurrDeclContext);
1756
1756
}
1757
1757
1758
+ Type CompletionLookup::getTypeAliasType (const TypeAliasDecl *TAD,
1759
+ DynamicLookupInfo dynamicLookupInfo) {
1760
+ // Substitute the base type for a nested typealias if needed.
1761
+ auto ty = getTypeOfMember (TAD, dynamicLookupInfo);
1762
+ auto *typeAliasTy = dyn_cast<TypeAliasType>(ty.getPointer ());
1763
+ if (!typeAliasTy)
1764
+ return ty;
1765
+
1766
+ // If the underlying type has an error, prefer to print the full typealias,
1767
+ // otherwise get the underlying type.
1768
+ Type underlyingTy = typeAliasTy->getSinglyDesugaredType ();
1769
+ if (underlyingTy->hasError ())
1770
+ return ty;
1771
+
1772
+ // The underlying type might be unbound for e.g:
1773
+ //
1774
+ // struct S<T> {}
1775
+ // typealias X = S
1776
+ //
1777
+ // Introduce type parameters such that we print the underlying type as
1778
+ // 'S<T>'.
1779
+ return underlyingTy.transformRec ([&](TypeBase *ty) -> std::optional<Type> {
1780
+ if (!ty->hasUnboundGenericType ()) {
1781
+ // Skip.
1782
+ return ty;
1783
+ }
1784
+ auto *UGT = dyn_cast<UnboundGenericType>(ty);
1785
+ if (!UGT) {
1786
+ // Recurse.
1787
+ return std::nullopt;
1788
+ }
1789
+ return UGT->getDecl ()->getDeclaredInterfaceType ();
1790
+ });
1791
+ }
1792
+
1758
1793
void CompletionLookup::addTypeAliasRef (const TypeAliasDecl *TAD,
1759
1794
DeclVisibilityKind Reason,
1760
1795
DynamicLookupInfo dynamicLookupInfo) {
@@ -1764,18 +1799,7 @@ void CompletionLookup::addTypeAliasRef(const TypeAliasDecl *TAD,
1764
1799
Builder.setAssociatedDecl (TAD);
1765
1800
addLeadingDot (Builder);
1766
1801
addValueBaseName (Builder, TAD->getBaseName ());
1767
-
1768
- // Substitute the base type for a nested typealias if needed.
1769
- auto ty = getTypeOfMember (TAD, dynamicLookupInfo);
1770
-
1771
- // If the underlying type has an error, prefer to print the full typealias,
1772
- // otherwise get the underlying type.
1773
- if (auto *TA = dyn_cast<TypeAliasType>(ty.getPointer ())) {
1774
- auto underlyingTy = TA->getSinglyDesugaredType ();
1775
- if (!underlyingTy->hasError ())
1776
- ty = underlyingTy;
1777
- }
1778
- addTypeAnnotation (Builder, ty);
1802
+ addTypeAnnotation (Builder, getTypeAliasType (TAD, dynamicLookupInfo));
1779
1803
}
1780
1804
1781
1805
void CompletionLookup::addGenericTypeParamRef (
0 commit comments