@@ -6055,7 +6055,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
6055
6055
switch (Options.OpaqueReturnTypePrinting ) {
6056
6056
case PrintOptions::OpaqueReturnTypePrintingMode::StableReference:
6057
6057
case PrintOptions::OpaqueReturnTypePrintingMode::Description:
6058
- return true ;
6058
+ return false ;
6059
6059
case PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword:
6060
6060
return opaque->getDecl ()->hasExplicitGenericParams ();
6061
6061
case PrintOptions::OpaqueReturnTypePrintingMode::WithoutOpaqueKeyword:
@@ -7413,39 +7413,51 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
7413
7413
Printer << " each " ;
7414
7414
}
7415
7415
7416
- void printArchetypeCommon (ArchetypeType *T) {
7417
- if (Options.AlternativeTypeNames ) {
7418
- auto found = Options.AlternativeTypeNames ->find (T->getCanonicalType ());
7419
- if (found != Options.AlternativeTypeNames ->end ()) {
7420
- if (T->isParameterPack ()) printEach ();
7421
- Printer << found->second .str ();
7422
- return ;
7416
+ void printArchetypeCommon (Type interfaceTy, ArchetypeType *archetypeTy) {
7417
+ if (auto *paramTy = interfaceTy->getAs <GenericTypeParamType>()) {
7418
+ assert (archetypeTy->isRoot ());
7419
+
7420
+ if (Options.AlternativeTypeNames ) {
7421
+ auto found = Options.AlternativeTypeNames ->find (CanType (archetypeTy));
7422
+ if (found != Options.AlternativeTypeNames ->end ()) {
7423
+ if (paramTy->isParameterPack ()) printEach ();
7424
+ Printer << found->second .str ();
7425
+ return ;
7426
+ }
7423
7427
}
7428
+
7429
+ visit (paramTy);
7430
+ return ;
7424
7431
}
7425
7432
7426
- auto interfaceType = T-> getInterfaceType ();
7427
- if (auto *dependentMember = interfaceType-> getAs <DependentMemberType >()) {
7428
- visitParentType (T-> getParent ());
7429
- printDependentMember (dependentMember);
7430
- } else {
7431
- visit (interfaceType) ;
7433
+ auto *memberTy = interfaceTy-> castTo <DependentMemberType> ();
7434
+ if (memberTy-> getBase ()-> is <GenericTypeParamType >())
7435
+ visitParentType (archetypeTy-> getRoot ());
7436
+ else {
7437
+ printArchetypeCommon (memberTy-> getBase (), archetypeTy-> getRoot ());
7438
+ Printer << " . " ;
7432
7439
}
7440
+
7441
+ printDependentMember (memberTy);
7433
7442
}
7434
7443
7435
7444
void visitPrimaryArchetypeType (PrimaryArchetypeType *T) {
7436
- printArchetypeCommon (T);
7445
+ printArchetypeCommon (T-> getInterfaceType (), T );
7437
7446
}
7438
7447
7439
7448
void visitOpaqueTypeArchetypeType (OpaqueTypeArchetypeType *T) {
7440
- if (auto parent = T->getParent ()) {
7441
- printArchetypeCommon (T);
7449
+ auto interfaceTy = T->getInterfaceType ();
7450
+ auto *paramTy = interfaceTy->getAs <GenericTypeParamType>();
7451
+
7452
+ if (!paramTy) {
7453
+ assert (interfaceTy->is <DependentMemberType>());
7454
+ printArchetypeCommon (interfaceTy, T);
7442
7455
return ;
7443
7456
}
7444
7457
7445
7458
// Try to print a named opaque type.
7446
7459
auto printNamedOpaque = [&] {
7447
- unsigned ordinal =
7448
- T->getInterfaceType ()->castTo <GenericTypeParamType>()->getIndex ();
7460
+ unsigned ordinal = paramTy->getIndex ();
7449
7461
if (auto genericParam = T->getDecl ()->getExplicitGenericParam (ordinal)) {
7450
7462
visit (genericParam->getDeclaredInterfaceType ());
7451
7463
return true ;
@@ -7492,9 +7504,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
7492
7504
Printer.printEscapedStringLiteral (
7493
7505
decl->getOpaqueReturnTypeIdentifier ().str ());
7494
7506
7495
- Printer << " , " << T->getInterfaceType ()
7496
- ->castTo <GenericTypeParamType>()
7497
- ->getIndex ();
7507
+ Printer << " , " << paramTy->getIndex ();
7498
7508
7499
7509
// The identifier after the closing parenthesis is irrelevant and can be
7500
7510
// anything. It just needs to be there for the @_opaqueReturnTypeOf
@@ -7526,7 +7536,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
7526
7536
}
7527
7537
7528
7538
void visitPackArchetypeType (PackArchetypeType *T) {
7529
- printArchetypeCommon (T);
7539
+ printArchetypeCommon (T-> getInterfaceType (), T );
7530
7540
}
7531
7541
7532
7542
void visitGenericTypeParamType (GenericTypeParamType *T) {
0 commit comments