@@ -7407,39 +7407,51 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
7407
7407
Printer << " each " ;
7408
7408
}
7409
7409
7410
- void printArchetypeCommon (ArchetypeType *T) {
7411
- if (Options.AlternativeTypeNames ) {
7412
- auto found = Options.AlternativeTypeNames ->find (T->getCanonicalType ());
7413
- if (found != Options.AlternativeTypeNames ->end ()) {
7414
- if (T->isParameterPack ()) printEach ();
7415
- Printer << found->second .str ();
7416
- return ;
7410
+ void printArchetypeCommon (Type interfaceTy, ArchetypeType *archetypeTy) {
7411
+ if (auto *paramTy = interfaceTy->getAs <GenericTypeParamType>()) {
7412
+ assert (archetypeTy->isRoot ());
7413
+
7414
+ if (Options.AlternativeTypeNames ) {
7415
+ auto found = Options.AlternativeTypeNames ->find (CanType (archetypeTy));
7416
+ if (found != Options.AlternativeTypeNames ->end ()) {
7417
+ if (paramTy->isParameterPack ()) printEach ();
7418
+ Printer << found->second .str ();
7419
+ return ;
7420
+ }
7417
7421
}
7422
+
7423
+ visit (paramTy);
7424
+ return ;
7418
7425
}
7419
7426
7420
- auto interfaceType = T-> getInterfaceType ();
7421
- if (auto *dependentMember = interfaceType-> getAs <DependentMemberType >()) {
7422
- visitParentType (T-> getParent ());
7423
- printDependentMember (dependentMember);
7424
- } else {
7425
- visit (interfaceType) ;
7427
+ auto *memberTy = interfaceTy-> castTo <DependentMemberType> ();
7428
+ if (memberTy-> getBase ()-> is <GenericTypeParamType >())
7429
+ visitParentType (archetypeTy-> getRoot ());
7430
+ else {
7431
+ printArchetypeCommon (memberTy-> getBase (), archetypeTy-> getRoot ());
7432
+ Printer << " . " ;
7426
7433
}
7434
+
7435
+ printDependentMember (memberTy);
7427
7436
}
7428
7437
7429
7438
void visitPrimaryArchetypeType (PrimaryArchetypeType *T) {
7430
- printArchetypeCommon (T);
7439
+ printArchetypeCommon (T-> getInterfaceType (), T );
7431
7440
}
7432
7441
7433
7442
void visitOpaqueTypeArchetypeType (OpaqueTypeArchetypeType *T) {
7434
- if (auto parent = T->getParent ()) {
7435
- printArchetypeCommon (T);
7443
+ auto interfaceTy = T->getInterfaceType ();
7444
+ auto *paramTy = interfaceTy->getAs <GenericTypeParamType>();
7445
+
7446
+ if (!paramTy) {
7447
+ assert (interfaceTy->is <DependentMemberType>());
7448
+ printArchetypeCommon (interfaceTy, T);
7436
7449
return ;
7437
7450
}
7438
7451
7439
7452
// Try to print a named opaque type.
7440
7453
auto printNamedOpaque = [&] {
7441
- unsigned ordinal =
7442
- T->getInterfaceType ()->castTo <GenericTypeParamType>()->getIndex ();
7454
+ unsigned ordinal = paramTy->getIndex ();
7443
7455
if (auto genericParam = T->getDecl ()->getExplicitGenericParam (ordinal)) {
7444
7456
visit (genericParam->getDeclaredInterfaceType ());
7445
7457
return true ;
@@ -7486,9 +7498,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
7486
7498
Printer.printEscapedStringLiteral (
7487
7499
decl->getOpaqueReturnTypeIdentifier ().str ());
7488
7500
7489
- Printer << " , " << T->getInterfaceType ()
7490
- ->castTo <GenericTypeParamType>()
7491
- ->getIndex ();
7501
+ Printer << " , " << paramTy->getIndex ();
7492
7502
7493
7503
// The identifier after the closing parenthesis is irrelevant and can be
7494
7504
// anything. It just needs to be there for the @_opaqueReturnTypeOf
@@ -7520,7 +7530,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
7520
7530
}
7521
7531
7522
7532
void visitPackArchetypeType (PackArchetypeType *T) {
7523
- printArchetypeCommon (T);
7533
+ printArchetypeCommon (T-> getInterfaceType (), T );
7524
7534
}
7525
7535
7526
7536
void visitGenericTypeParamType (GenericTypeParamType *T) {
0 commit comments