@@ -5282,15 +5282,20 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
52825282 Optional<llvm::DenseMap<const clang::Module *, ModuleDecl *>>
52835283 VisibleClangModules;
52845284
5285- void printGenericArgs (ArrayRef<Type> Args) {
5286- if (Args.empty ())
5287- return ;
5288-
5285+ void printGenericArgs (PackType *flatArgs) {
52895286 Printer << " <" ;
5290- interleave (Args, [&](Type Arg) { visit (Arg); }, [&] { Printer << " , " ; });
5287+ interleave (flatArgs->getElementTypes (),
5288+ [&](Type arg) { visit (arg); },
5289+ [&] { Printer << " , " ; });
52915290 Printer << " >" ;
52925291 }
52935292
5293+ void printGenericArgs (ASTContext &ctx,
5294+ TypeArrayView<GenericTypeParamType> params,
5295+ ArrayRef<Type> args) {
5296+ printGenericArgs (PackType::get (ctx, params, args));
5297+ }
5298+
52945299 // / Helper function for printing a type that is embedded within a larger type.
52955300 // /
52965301 // / This is necessary whenever the inner type may not normally be represented
@@ -5626,7 +5631,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
56265631 }
56275632
56285633 printQualifiedType (T);
5629- printGenericArgs (T->getDirectGenericArgs ());
5634+
5635+ auto *typeAliasDecl = T->getDecl ();
5636+ if (typeAliasDecl->isGeneric ()) {
5637+ printGenericArgs (T->getExpandedGenericArgsPack ());
5638+ }
56305639 }
56315640
56325641 void visitParenType (ParenType *T) {
@@ -5711,7 +5720,8 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
57115720 }
57125721 }
57135722 printQualifiedType (T);
5714- printGenericArgs (T->getGenericArgs ());
5723+
5724+ printGenericArgs (T->getExpandedGenericArgsPack ());
57155725 }
57165726
57175727 void visitParentType (Type T) {
@@ -6525,6 +6535,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
65256535 return false ;
65266536 };
65276537
6538+ OpaqueTypeDecl *decl = T->getDecl ();
6539+ auto *namingDecl = decl->getNamingDecl ();
6540+ auto genericSig = namingDecl->getInnermostDeclContext ()
6541+ ->getGenericSignatureOfContext ();
6542+
65286543 switch (Options.OpaqueReturnTypePrinting ) {
65296544 case PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword:
65306545 if (printNamedOpaque ())
@@ -6542,8 +6557,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
65426557
65436558 // Opaque archetype substitutions are always canonical, so re-sugar the
65446559 // constraint type using the owning declaration's generic parameter names.
6545- auto genericSig = T->getDecl ()->getNamingDecl ()->getInnermostDeclContext ()
6546- ->getGenericSignatureOfContext ();
65476560 if (genericSig)
65486561 constraint = genericSig->getSugaredType (constraint);
65496562
@@ -6556,7 +6569,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
65566569 // turn this back into a reference to the naming decl for the opaque
65576570 // type.
65586571 Printer << " @_opaqueReturnTypeOf(" ;
6559- OpaqueTypeDecl *decl = T->getDecl ();
65606572
65616573 Printer.printEscapedStringLiteral (
65626574 decl->getOpaqueReturnTypeIdentifier ().str ());
@@ -6570,22 +6582,24 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
65706582 // attribute to apply to, but the attribute alone references the opaque
65716583 // type.
65726584 Printer << " ) __" ;
6573- printGenericArgs (T->getSubstitutions ().getReplacementTypes ());
6585+
6586+ if (genericSig) {
6587+ printGenericArgs (decl->getASTContext (),
6588+ genericSig.getGenericParams (),
6589+ T->getSubstitutions ().getReplacementTypes ());
6590+ }
65746591 return ;
65756592 }
65766593 case PrintOptions::OpaqueReturnTypePrintingMode::Description: {
65776594 // TODO(opaque): present opaque types with user-facing syntax. we should
65786595 // probably print this as `some P` and record the fact that we printed that
65796596 // so that diagnostics can add followup notes.
6580- Printer << " (return type of " << T-> getDecl ()-> getNamingDecl () ->printRef ();
6597+ Printer << " (return type of " << namingDecl ->printRef ();
65816598 Printer << ' )' ;
6582- if (!T->getSubstitutions ().empty ()) {
6583- Printer << ' <' ;
6584- auto replacements = T->getSubstitutions ().getReplacementTypes ();
6585- llvm::interleave (
6586- replacements.begin (), replacements.end (), [&](Type t) { visit (t); },
6587- [&] { Printer << " , " ; });
6588- Printer << ' >' ;
6599+ if (genericSig) {
6600+ printGenericArgs (decl->getASTContext (),
6601+ genericSig.getGenericParams (),
6602+ T->getSubstitutions ().getReplacementTypes ());
65896603 }
65906604 return ;
65916605 }
0 commit comments