@@ -6055,7 +6055,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
60556055 switch (Options.OpaqueReturnTypePrinting ) {
60566056 case PrintOptions::OpaqueReturnTypePrintingMode::StableReference:
60576057 case PrintOptions::OpaqueReturnTypePrintingMode::Description:
6058- return true ;
6058+ return false ;
60596059 case PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword:
60606060 return opaque->getDecl ()->hasExplicitGenericParams ();
60616061 case PrintOptions::OpaqueReturnTypePrintingMode::WithoutOpaqueKeyword:
@@ -7413,39 +7413,51 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
74137413 Printer << " each " ;
74147414 }
74157415
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+ }
74237427 }
7428+
7429+ visit (paramTy);
7430+ return ;
74247431 }
74257432
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 << " . " ;
74327439 }
7440+
7441+ printDependentMember (memberTy);
74337442 }
74347443
74357444 void visitPrimaryArchetypeType (PrimaryArchetypeType *T) {
7436- printArchetypeCommon (T);
7445+ printArchetypeCommon (T-> getInterfaceType (), T );
74377446 }
74387447
74397448 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);
74427455 return ;
74437456 }
74447457
74457458 // Try to print a named opaque type.
74467459 auto printNamedOpaque = [&] {
7447- unsigned ordinal =
7448- T->getInterfaceType ()->castTo <GenericTypeParamType>()->getIndex ();
7460+ unsigned ordinal = paramTy->getIndex ();
74497461 if (auto genericParam = T->getDecl ()->getExplicitGenericParam (ordinal)) {
74507462 visit (genericParam->getDeclaredInterfaceType ());
74517463 return true ;
@@ -7492,9 +7504,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
74927504 Printer.printEscapedStringLiteral (
74937505 decl->getOpaqueReturnTypeIdentifier ().str ());
74947506
7495- Printer << " , " << T->getInterfaceType ()
7496- ->castTo <GenericTypeParamType>()
7497- ->getIndex ();
7507+ Printer << " , " << paramTy->getIndex ();
74987508
74997509 // The identifier after the closing parenthesis is irrelevant and can be
75007510 // anything. It just needs to be there for the @_opaqueReturnTypeOf
@@ -7526,7 +7536,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
75267536 }
75277537
75287538 void visitPackArchetypeType (PackArchetypeType *T) {
7529- printArchetypeCommon (T);
7539+ printArchetypeCommon (T-> getInterfaceType (), T );
75307540 }
75317541
75327542 void visitGenericTypeParamType (GenericTypeParamType *T) {
0 commit comments