@@ -5282,15 +5282,20 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
5282
5282
Optional<llvm::DenseMap<const clang::Module *, ModuleDecl *>>
5283
5283
VisibleClangModules;
5284
5284
5285
- void printGenericArgs (ArrayRef<Type> Args) {
5286
- if (Args.empty ())
5287
- return ;
5288
-
5285
+ void printGenericArgs (PackType *flatArgs) {
5289
5286
Printer << " <" ;
5290
- interleave (Args, [&](Type Arg) { visit (Arg); }, [&] { Printer << " , " ; });
5287
+ interleave (flatArgs->getElementTypes (),
5288
+ [&](Type arg) { visit (arg); },
5289
+ [&] { Printer << " , " ; });
5291
5290
Printer << " >" ;
5292
5291
}
5293
5292
5293
+ void printGenericArgs (ASTContext &ctx,
5294
+ TypeArrayView<GenericTypeParamType> params,
5295
+ ArrayRef<Type> args) {
5296
+ printGenericArgs (PackType::get (ctx, params, args));
5297
+ }
5298
+
5294
5299
// / Helper function for printing a type that is embedded within a larger type.
5295
5300
// /
5296
5301
// / This is necessary whenever the inner type may not normally be represented
@@ -5626,7 +5631,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
5626
5631
}
5627
5632
5628
5633
printQualifiedType (T);
5629
- printGenericArgs (T->getDirectGenericArgs ());
5634
+
5635
+ auto *typeAliasDecl = T->getDecl ();
5636
+ if (typeAliasDecl->isGeneric ()) {
5637
+ printGenericArgs (T->getExpandedGenericArgsPack ());
5638
+ }
5630
5639
}
5631
5640
5632
5641
void visitParenType (ParenType *T) {
@@ -5711,7 +5720,8 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
5711
5720
}
5712
5721
}
5713
5722
printQualifiedType (T);
5714
- printGenericArgs (T->getGenericArgs ());
5723
+
5724
+ printGenericArgs (T->getExpandedGenericArgsPack ());
5715
5725
}
5716
5726
5717
5727
void visitParentType (Type T) {
@@ -6525,6 +6535,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
6525
6535
return false ;
6526
6536
};
6527
6537
6538
+ OpaqueTypeDecl *decl = T->getDecl ();
6539
+ auto *namingDecl = decl->getNamingDecl ();
6540
+ auto genericSig = namingDecl->getInnermostDeclContext ()
6541
+ ->getGenericSignatureOfContext ();
6542
+
6528
6543
switch (Options.OpaqueReturnTypePrinting ) {
6529
6544
case PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword:
6530
6545
if (printNamedOpaque ())
@@ -6542,8 +6557,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
6542
6557
6543
6558
// Opaque archetype substitutions are always canonical, so re-sugar the
6544
6559
// constraint type using the owning declaration's generic parameter names.
6545
- auto genericSig = T->getDecl ()->getNamingDecl ()->getInnermostDeclContext ()
6546
- ->getGenericSignatureOfContext ();
6547
6560
if (genericSig)
6548
6561
constraint = genericSig->getSugaredType (constraint);
6549
6562
@@ -6556,7 +6569,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
6556
6569
// turn this back into a reference to the naming decl for the opaque
6557
6570
// type.
6558
6571
Printer << " @_opaqueReturnTypeOf(" ;
6559
- OpaqueTypeDecl *decl = T->getDecl ();
6560
6572
6561
6573
Printer.printEscapedStringLiteral (
6562
6574
decl->getOpaqueReturnTypeIdentifier ().str ());
@@ -6570,22 +6582,24 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
6570
6582
// attribute to apply to, but the attribute alone references the opaque
6571
6583
// type.
6572
6584
Printer << " ) __" ;
6573
- printGenericArgs (T->getSubstitutions ().getReplacementTypes ());
6585
+
6586
+ if (genericSig) {
6587
+ printGenericArgs (decl->getASTContext (),
6588
+ genericSig.getGenericParams (),
6589
+ T->getSubstitutions ().getReplacementTypes ());
6590
+ }
6574
6591
return ;
6575
6592
}
6576
6593
case PrintOptions::OpaqueReturnTypePrintingMode::Description: {
6577
6594
// TODO(opaque): present opaque types with user-facing syntax. we should
6578
6595
// probably print this as `some P` and record the fact that we printed that
6579
6596
// so that diagnostics can add followup notes.
6580
- Printer << " (return type of " << T-> getDecl ()-> getNamingDecl () ->printRef ();
6597
+ Printer << " (return type of " << namingDecl ->printRef ();
6581
6598
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 ());
6589
6603
}
6590
6604
return ;
6591
6605
}
0 commit comments