@@ -5581,38 +5581,30 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
5581
5581
}
5582
5582
5583
5583
Type instanceType = T->getInstanceType ();
5584
- bool didPrintInstanceType = false ;
5585
- if (Options.PrintExplicitAny ) {
5586
- if (T->is <ExistentialMetatypeType>()) {
5587
- Printer << " any " ;
5588
-
5589
- // FIXME: We need to replace nested existential metatypes so that
5590
- // we don't print duplicate 'any'. This will be unnecessary once
5591
- // ExistentialMetatypeType is split into ExistentialType(MetatypeType).
5592
- instanceType = Type (instanceType).transform ([](Type type) -> Type {
5593
- if (auto existential = type->getAs <ExistentialMetatypeType>())
5594
- return MetatypeType::get (existential->getInstanceType ());
5595
-
5596
- return type;
5597
- });
5598
- } else if (auto existential = instanceType->getAs <ExistentialType>()) {
5599
- // The 'any' keyword is needed to distinguish between existential
5600
- // metatypes and singleton metatypes. However, 'any' usually isn't
5601
- // printed for Any and AnyObject, because it's unnecessary to write
5602
- // 'any' with these specific constraints. Set a bit on the existential
5603
- // type to force printing with 'any' for metatypes. This bit doesn't
5604
- // matter for anything other than printing.
5605
- if (!existential->shouldPrintWithAny ()) {
5606
- existential->forcePrintWithAny (true );
5607
- printWithParensIfNotSimple (existential);
5608
- existential->forcePrintWithAny (false );
5609
- didPrintInstanceType = true ;
5610
- }
5611
- }
5612
- }
5584
+ if (Options.PrintExplicitAny && T->is <ExistentialMetatypeType>()) {
5585
+ Printer << " any " ;
5586
+
5587
+ // FIXME: We need to replace nested existential metatypes so that
5588
+ // we don't print duplicate 'any'. This will be unnecessary once
5589
+ // ExistentialMetatypeType is split into ExistentialType(MetatypeType).
5590
+ printWithParensIfNotSimple (instanceType.transform ([](Type type) -> Type {
5591
+ if (auto existential = type->getAs <ExistentialMetatypeType>())
5592
+ return MetatypeType::get (existential->getInstanceType ());
5613
5593
5614
- if (!didPrintInstanceType)
5594
+ return type;
5595
+ }));
5596
+ } else if (T->is <MetatypeType>() && instanceType->is <ExistentialType>()) {
5597
+ // The 'any' keyword is needed to distinguish between existential
5598
+ // metatypes and singleton metatypes. However, 'any' usually isn't
5599
+ // printed for Any and AnyObject, because it's unnecessary to write
5600
+ // 'any' with these specific constraints. Force printing with 'any'
5601
+ // for the existential instance type in this case.
5602
+ instanceType->getAs <ExistentialType>()->forcePrintWithAny ([&](Type ty) {
5603
+ printWithParensIfNotSimple (ty);
5604
+ });
5605
+ } else {
5615
5606
printWithParensIfNotSimple (instanceType);
5607
+ }
5616
5608
5617
5609
// We spell normal metatypes of existential types as .Protocol.
5618
5610
if (isa<MetatypeType>(T) &&
0 commit comments