Skip to content

Commit 0b29ba9

Browse files
committed
[TypeResolver] Don't use ExistentialType for Any and AnyObject for
now.
1 parent 3cd6032 commit 0b29ba9

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/AST/ASTDemangler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,8 @@ Type ASTBuilder::createProtocolCompositionType(
590590
if (superclass && superclass->getClassOrBoundGenericClass())
591591
members.push_back(superclass);
592592
Type composition = ProtocolCompositionType::get(Ctx, members, isClassBound);
593-
if (Ctx.LangOpts.EnableExplicitExistentialTypes) {
593+
if (Ctx.LangOpts.EnableExplicitExistentialTypes &&
594+
!(composition->isAny() || composition->isAnyObject())) {
594595
composition = ExistentialType::get(composition);
595596
}
596597
return composition;

lib/Sema/TypeCheckType.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,8 +3364,9 @@ TypeResolver::resolveIdentifierType(IdentTypeRepr *IdType,
33643364
return ErrorType::get(getASTContext());
33653365
}
33663366

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());
33693370
if (isConstraintType &&
33703371
getASTContext().LangOpts.EnableExplicitExistentialTypes &&
33713372
options.isConstraintImplicitExistential()) {
@@ -3738,7 +3739,8 @@ TypeResolver::resolveCompositionType(CompositionTypeRepr *repr,
37383739
ProtocolCompositionType::get(getASTContext(), Members,
37393740
/*HasExplicitAnyObject=*/false);
37403741
if (getASTContext().LangOpts.EnableExplicitExistentialTypes &&
3741-
options.isConstraintImplicitExistential()) {
3742+
options.isConstraintImplicitExistential() &&
3743+
!composition->isAny()) {
37423744
composition = ExistentialType::get(composition);
37433745
}
37443746
return composition;
@@ -3767,6 +3769,7 @@ TypeResolver::resolveExistentialType(ExistentialTypeRepr *repr,
37673769
diagnose(repr->getLoc(), diag::unnecessary_any,
37683770
constraintType)
37693771
.fixItRemove({anyStart, anyEnd});
3772+
return constraintType;
37703773
}
37713774

37723775
return ExistentialType::get(constraintType);
@@ -3954,7 +3957,7 @@ class ExistentialTypeVisitor
39543957
// Arbitrary protocol constraints are okay for 'any' types.
39553958
if (isa<ExistentialTypeRepr>(T))
39563959
return false;
3957-
3960+
39583961
visit(T);
39593962
return true;
39603963
}

0 commit comments

Comments
 (0)