@@ -3966,7 +3966,8 @@ class ExistentialTypeVisitor
39663966 return false ;
39673967
39683968 // Arbitrary protocol constraints are okay for 'any' types.
3969- if (isa<ExistentialTypeRepr>(T))
3969+ if (Ctx.LangOpts .EnableExperimentalUniversalExistentials &&
3970+ isa<ExistentialTypeRepr>(T))
39703971 return false ;
39713972
39723973 visit (T);
@@ -3991,16 +3992,23 @@ class ExistentialTypeVisitor
39913992 }
39923993
39933994 void visitIdentTypeRepr (IdentTypeRepr *T) {
3994- if (T->isInvalid () || !Ctx. LangOpts . EnableExplicitExistentialTypes )
3995+ if (T->isInvalid ())
39953996 return ;
39963997
39973998 auto comp = T->getComponentRange ().back ();
39983999 if (auto *proto = dyn_cast_or_null<ProtocolDecl>(comp->getBoundDecl ())) {
39994000 if (proto->existentialRequiresAny ()) {
4000- Ctx.Diags .diagnose (comp->getNameLoc (),
4001- diag::existential_requires_any,
4002- proto->getName ())
4003- .limitBehavior (DiagnosticBehavior::Warning);
4001+ if (!Ctx.LangOpts .EnableExperimentalUniversalExistentials ) {
4002+ Ctx.Diags .diagnose (comp->getNameLoc (),
4003+ diag::unsupported_existential_type,
4004+ proto->getName ());
4005+ T->setInvalid ();
4006+ } else if (Ctx.LangOpts .EnableExplicitExistentialTypes ) {
4007+ Ctx.Diags .diagnose (comp->getNameLoc (),
4008+ diag::existential_requires_any,
4009+ proto->getName ())
4010+ .limitBehavior (DiagnosticBehavior::Warning);
4011+ }
40044012 }
40054013 } else if (auto *alias = dyn_cast_or_null<TypeAliasDecl>(comp->getBoundDecl ())) {
40064014 auto type = Type (alias->getDeclaredInterfaceType ()->getDesugaredType ());
@@ -4014,10 +4022,17 @@ class ExistentialTypeVisitor
40144022 if (!protoDecl->existentialRequiresAny ())
40154023 continue ;
40164024
4017- Ctx.Diags .diagnose (comp->getNameLoc (),
4018- diag::existential_requires_any,
4019- protoDecl->getName ())
4020- .limitBehavior (DiagnosticBehavior::Warning);
4025+ if (!Ctx.LangOpts .EnableExperimentalUniversalExistentials ) {
4026+ Ctx.Diags .diagnose (comp->getNameLoc (),
4027+ diag::unsupported_existential_type,
4028+ protoDecl->getName ());
4029+ T->setInvalid ();
4030+ } else if (Ctx.LangOpts .EnableExplicitExistentialTypes ) {
4031+ Ctx.Diags .diagnose (comp->getNameLoc (),
4032+ diag::existential_requires_any,
4033+ protoDecl->getName ())
4034+ .limitBehavior (DiagnosticBehavior::Warning);
4035+ }
40214036 }
40224037 }
40234038 return false ;
0 commit comments