@@ -5294,15 +5294,20 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
5294
5294
Optional<llvm::DenseMap<const clang::Module *, ModuleDecl *>>
5295
5295
VisibleClangModules;
5296
5296
5297
- void printGenericArgs (ArrayRef<Type> Args) {
5298
- if (Args.empty ())
5299
- return ;
5300
-
5297
+ void printGenericArgs (PackType *flatArgs) {
5301
5298
Printer << " <" ;
5302
- interleave (Args, [&](Type Arg) { visit (Arg); }, [&] { Printer << " , " ; });
5299
+ interleave (flatArgs->getElementTypes (),
5300
+ [&](Type arg) { visit (arg); },
5301
+ [&] { Printer << " , " ; });
5303
5302
Printer << " >" ;
5304
5303
}
5305
5304
5305
+ void printGenericArgs (ASTContext &ctx,
5306
+ TypeArrayView<GenericTypeParamType> params,
5307
+ ArrayRef<Type> args) {
5308
+ printGenericArgs (PackType::get (ctx, params, args));
5309
+ }
5310
+
5306
5311
// / Helper function for printing a type that is embedded within a larger type.
5307
5312
// /
5308
5313
// / This is necessary whenever the inner type may not normally be represented
@@ -5638,7 +5643,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
5638
5643
}
5639
5644
5640
5645
printQualifiedType (T);
5641
- printGenericArgs (T->getDirectGenericArgs ());
5646
+
5647
+ auto *typeAliasDecl = T->getDecl ();
5648
+ if (typeAliasDecl->isGeneric ()) {
5649
+ printGenericArgs (T->getExpandedGenericArgsPack ());
5650
+ }
5642
5651
}
5643
5652
5644
5653
void visitParenType (ParenType *T) {
@@ -5723,7 +5732,8 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
5723
5732
}
5724
5733
}
5725
5734
printQualifiedType (T);
5726
- printGenericArgs (T->getGenericArgs ());
5735
+
5736
+ printGenericArgs (T->getExpandedGenericArgsPack ());
5727
5737
}
5728
5738
5729
5739
void visitParentType (Type T) {
@@ -6537,6 +6547,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
6537
6547
return false ;
6538
6548
};
6539
6549
6550
+ OpaqueTypeDecl *decl = T->getDecl ();
6551
+ auto *namingDecl = decl->getNamingDecl ();
6552
+ auto genericSig = namingDecl->getInnermostDeclContext ()
6553
+ ->getGenericSignatureOfContext ();
6554
+
6540
6555
switch (Options.OpaqueReturnTypePrinting ) {
6541
6556
case PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword:
6542
6557
if (printNamedOpaque ())
@@ -6554,8 +6569,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
6554
6569
6555
6570
// Opaque archetype substitutions are always canonical, so re-sugar the
6556
6571
// constraint type using the owning declaration's generic parameter names.
6557
- auto genericSig = T->getDecl ()->getNamingDecl ()->getInnermostDeclContext ()
6558
- ->getGenericSignatureOfContext ();
6559
6572
if (genericSig)
6560
6573
constraint = genericSig->getSugaredType (constraint);
6561
6574
@@ -6568,7 +6581,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
6568
6581
// turn this back into a reference to the naming decl for the opaque
6569
6582
// type.
6570
6583
Printer << " @_opaqueReturnTypeOf(" ;
6571
- OpaqueTypeDecl *decl = T->getDecl ();
6572
6584
6573
6585
Printer.printEscapedStringLiteral (
6574
6586
decl->getOpaqueReturnTypeIdentifier ().str ());
@@ -6582,22 +6594,24 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
6582
6594
// attribute to apply to, but the attribute alone references the opaque
6583
6595
// type.
6584
6596
Printer << " ) __" ;
6585
- printGenericArgs (T->getSubstitutions ().getReplacementTypes ());
6597
+
6598
+ if (genericSig) {
6599
+ printGenericArgs (decl->getASTContext (),
6600
+ genericSig.getGenericParams (),
6601
+ T->getSubstitutions ().getReplacementTypes ());
6602
+ }
6586
6603
return ;
6587
6604
}
6588
6605
case PrintOptions::OpaqueReturnTypePrintingMode::Description: {
6589
6606
// TODO(opaque): present opaque types with user-facing syntax. we should
6590
6607
// probably print this as `some P` and record the fact that we printed that
6591
6608
// so that diagnostics can add followup notes.
6592
- Printer << " (return type of " << T-> getDecl ()-> getNamingDecl () ->printRef ();
6609
+ Printer << " (return type of " << namingDecl ->printRef ();
6593
6610
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 ());
6601
6615
}
6602
6616
return ;
6603
6617
}
0 commit comments