@@ -3364,8 +3364,9 @@ TypeResolver::resolveIdentifierType(IdentTypeRepr *IdType,
3364
3364
return ErrorType::get (getASTContext ());
3365
3365
}
3366
3366
3367
- bool isConstraintType = (result->is <ProtocolType>() ||
3368
- result->is <ProtocolCompositionType>());
3367
+ // FIXME: Don't use ExistentialType for AnyObject for now.
3368
+ bool isConstraintType = (result->is <ProtocolType>() &&
3369
+ !result->isAnyObject ());
3369
3370
if (isConstraintType &&
3370
3371
getASTContext ().LangOpts .EnableExplicitExistentialTypes &&
3371
3372
options.isConstraintImplicitExistential ()) {
@@ -3738,7 +3739,8 @@ TypeResolver::resolveCompositionType(CompositionTypeRepr *repr,
3738
3739
ProtocolCompositionType::get (getASTContext (), Members,
3739
3740
/* HasExplicitAnyObject=*/ false );
3740
3741
if (getASTContext ().LangOpts .EnableExplicitExistentialTypes &&
3741
- options.isConstraintImplicitExistential ()) {
3742
+ options.isConstraintImplicitExistential () &&
3743
+ !composition->isAny ()) {
3742
3744
composition = ExistentialType::get (composition);
3743
3745
}
3744
3746
return composition;
@@ -3767,6 +3769,7 @@ TypeResolver::resolveExistentialType(ExistentialTypeRepr *repr,
3767
3769
diagnose (repr->getLoc (), diag::unnecessary_any,
3768
3770
constraintType)
3769
3771
.fixItRemove ({anyStart, anyEnd});
3772
+ return constraintType;
3770
3773
}
3771
3774
3772
3775
return ExistentialType::get (constraintType);
@@ -3954,7 +3957,7 @@ class ExistentialTypeVisitor
3954
3957
// Arbitrary protocol constraints are okay for 'any' types.
3955
3958
if (isa<ExistentialTypeRepr>(T))
3956
3959
return false ;
3957
-
3960
+
3958
3961
visit (T);
3959
3962
return true ;
3960
3963
}
0 commit comments