@@ -5294,15 +5294,20 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
52945294 Optional<llvm::DenseMap<const clang::Module *, ModuleDecl *>>
52955295 VisibleClangModules;
52965296
5297- void printGenericArgs (ArrayRef<Type> Args) {
5298- if (Args.empty ())
5299- return ;
5300-
5297+ void printGenericArgs (PackType *flatArgs) {
53015298 Printer << " <" ;
5302- interleave (Args, [&](Type Arg) { visit (Arg); }, [&] { Printer << " , " ; });
5299+ interleave (flatArgs->getElementTypes (),
5300+ [&](Type arg) { visit (arg); },
5301+ [&] { Printer << " , " ; });
53035302 Printer << " >" ;
53045303 }
53055304
5305+ void printGenericArgs (ASTContext &ctx,
5306+ TypeArrayView<GenericTypeParamType> params,
5307+ ArrayRef<Type> args) {
5308+ printGenericArgs (PackType::get (ctx, params, args));
5309+ }
5310+
53065311 // / Helper function for printing a type that is embedded within a larger type.
53075312 // /
53085313 // / This is necessary whenever the inner type may not normally be represented
@@ -5638,7 +5643,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
56385643 }
56395644
56405645 printQualifiedType (T);
5641- printGenericArgs (T->getDirectGenericArgs ());
5646+
5647+ auto *typeAliasDecl = T->getDecl ();
5648+ if (typeAliasDecl->isGeneric ()) {
5649+ printGenericArgs (T->getExpandedGenericArgsPack ());
5650+ }
56425651 }
56435652
56445653 void visitParenType (ParenType *T) {
@@ -5723,7 +5732,8 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
57235732 }
57245733 }
57255734 printQualifiedType (T);
5726- printGenericArgs (T->getGenericArgs ());
5735+
5736+ printGenericArgs (T->getExpandedGenericArgsPack ());
57275737 }
57285738
57295739 void visitParentType (Type T) {
@@ -6537,6 +6547,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
65376547 return false ;
65386548 };
65396549
6550+ OpaqueTypeDecl *decl = T->getDecl ();
6551+ auto *namingDecl = decl->getNamingDecl ();
6552+ auto genericSig = namingDecl->getInnermostDeclContext ()
6553+ ->getGenericSignatureOfContext ();
6554+
65406555 switch (Options.OpaqueReturnTypePrinting ) {
65416556 case PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword:
65426557 if (printNamedOpaque ())
@@ -6554,8 +6569,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
65546569
65556570 // Opaque archetype substitutions are always canonical, so re-sugar the
65566571 // constraint type using the owning declaration's generic parameter names.
6557- auto genericSig = T->getDecl ()->getNamingDecl ()->getInnermostDeclContext ()
6558- ->getGenericSignatureOfContext ();
65596572 if (genericSig)
65606573 constraint = genericSig->getSugaredType (constraint);
65616574
@@ -6568,7 +6581,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
65686581 // turn this back into a reference to the naming decl for the opaque
65696582 // type.
65706583 Printer << " @_opaqueReturnTypeOf(" ;
6571- OpaqueTypeDecl *decl = T->getDecl ();
65726584
65736585 Printer.printEscapedStringLiteral (
65746586 decl->getOpaqueReturnTypeIdentifier ().str ());
@@ -6582,22 +6594,24 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
65826594 // attribute to apply to, but the attribute alone references the opaque
65836595 // type.
65846596 Printer << " ) __" ;
6585- printGenericArgs (T->getSubstitutions ().getReplacementTypes ());
6597+
6598+ if (genericSig) {
6599+ printGenericArgs (decl->getASTContext (),
6600+ genericSig.getGenericParams (),
6601+ T->getSubstitutions ().getReplacementTypes ());
6602+ }
65866603 return ;
65876604 }
65886605 case PrintOptions::OpaqueReturnTypePrintingMode::Description: {
65896606 // TODO(opaque): present opaque types with user-facing syntax. we should
65906607 // probably print this as `some P` and record the fact that we printed that
65916608 // so that diagnostics can add followup notes.
6592- Printer << " (return type of " << T-> getDecl ()-> getNamingDecl () ->printRef ();
6609+ Printer << " (return type of " << namingDecl ->printRef ();
65936610 Printer << ' )' ;
6594- if (!T->getSubstitutions ().empty ()) {
6595- Printer << ' <' ;
6596- auto replacements = T->getSubstitutions ().getReplacementTypes ();
6597- llvm::interleave (
6598- replacements.begin (), replacements.end (), [&](Type t) { visit (t); },
6599- [&] { Printer << " , " ; });
6600- Printer << ' >' ;
6611+ if (genericSig) {
6612+ printGenericArgs (decl->getASTContext (),
6613+ genericSig.getGenericParams (),
6614+ T->getSubstitutions ().getReplacementTypes ());
66016615 }
66026616 return ;
66036617 }
0 commit comments