@@ -3966,7 +3966,8 @@ class ExistentialTypeVisitor
3966
3966
return false ;
3967
3967
3968
3968
// Arbitrary protocol constraints are okay for 'any' types.
3969
- if (isa<ExistentialTypeRepr>(T))
3969
+ if (Ctx.LangOpts .EnableExperimentalUniversalExistentials &&
3970
+ isa<ExistentialTypeRepr>(T))
3970
3971
return false ;
3971
3972
3972
3973
visit (T);
@@ -3991,16 +3992,23 @@ class ExistentialTypeVisitor
3991
3992
}
3992
3993
3993
3994
void visitIdentTypeRepr (IdentTypeRepr *T) {
3994
- if (T->isInvalid () || !Ctx. LangOpts . EnableExplicitExistentialTypes )
3995
+ if (T->isInvalid ())
3995
3996
return ;
3996
3997
3997
3998
auto comp = T->getComponentRange ().back ();
3998
3999
if (auto *proto = dyn_cast_or_null<ProtocolDecl>(comp->getBoundDecl ())) {
3999
4000
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
+ }
4004
4012
}
4005
4013
} else if (auto *alias = dyn_cast_or_null<TypeAliasDecl>(comp->getBoundDecl ())) {
4006
4014
auto type = Type (alias->getDeclaredInterfaceType ()->getDesugaredType ());
@@ -4014,10 +4022,17 @@ class ExistentialTypeVisitor
4014
4022
if (!protoDecl->existentialRequiresAny ())
4015
4023
continue ;
4016
4024
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
+ }
4021
4036
}
4022
4037
}
4023
4038
return false ;
0 commit comments