@@ -3382,8 +3382,9 @@ TypeResolver::resolveIdentifierType(IdentTypeRepr *IdType,
3382
3382
return ErrorType::get (getASTContext ());
3383
3383
}
3384
3384
3385
- bool isConstraintType = (result->is <ProtocolType>() ||
3386
- result->is <ProtocolCompositionType>());
3385
+ // FIXME: Don't use ExistentialType for AnyObject for now.
3386
+ bool isConstraintType = (result->is <ProtocolType>() &&
3387
+ !result->isAnyObject ());
3387
3388
if (isConstraintType &&
3388
3389
getASTContext ().LangOpts .EnableExplicitExistentialTypes &&
3389
3390
options.isConstraintImplicitExistential ()) {
@@ -3756,7 +3757,8 @@ TypeResolver::resolveCompositionType(CompositionTypeRepr *repr,
3756
3757
ProtocolCompositionType::get (getASTContext (), Members,
3757
3758
/* HasExplicitAnyObject=*/ false );
3758
3759
if (getASTContext ().LangOpts .EnableExplicitExistentialTypes &&
3759
- options.isConstraintImplicitExistential ()) {
3760
+ options.isConstraintImplicitExistential () &&
3761
+ !composition->isAny ()) {
3760
3762
composition = ExistentialType::get (composition);
3761
3763
}
3762
3764
return composition;
@@ -3785,6 +3787,7 @@ TypeResolver::resolveExistentialType(ExistentialTypeRepr *repr,
3785
3787
diagnose (repr->getLoc (), diag::unnecessary_any,
3786
3788
constraintType)
3787
3789
.fixItRemove ({anyStart, anyEnd});
3790
+ return constraintType;
3788
3791
}
3789
3792
3790
3793
return ExistentialType::get (constraintType);
@@ -3972,7 +3975,7 @@ class ExistentialTypeVisitor
3972
3975
// Arbitrary protocol constraints are okay for 'any' types.
3973
3976
if (isa<ExistentialTypeRepr>(T))
3974
3977
return false ;
3975
-
3978
+
3976
3979
visit (T);
3977
3980
return true ;
3978
3981
}
0 commit comments