Skip to content

Commit c142194

Browse files
committed
[TypeResolver] Don't use ExistentialType for Any and AnyObject for
now.
1 parent f6b58cc commit c142194

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
@@ -3382,8 +3382,9 @@ TypeResolver::resolveIdentifierType(IdentTypeRepr *IdType,
33823382
return ErrorType::get(getASTContext());
33833383
}
33843384

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());
33873388
if (isConstraintType &&
33883389
getASTContext().LangOpts.EnableExplicitExistentialTypes &&
33893390
options.isConstraintImplicitExistential()) {
@@ -3756,7 +3757,8 @@ TypeResolver::resolveCompositionType(CompositionTypeRepr *repr,
37563757
ProtocolCompositionType::get(getASTContext(), Members,
37573758
/*HasExplicitAnyObject=*/false);
37583759
if (getASTContext().LangOpts.EnableExplicitExistentialTypes &&
3759-
options.isConstraintImplicitExistential()) {
3760+
options.isConstraintImplicitExistential() &&
3761+
!composition->isAny()) {
37603762
composition = ExistentialType::get(composition);
37613763
}
37623764
return composition;
@@ -3785,6 +3787,7 @@ TypeResolver::resolveExistentialType(ExistentialTypeRepr *repr,
37853787
diagnose(repr->getLoc(), diag::unnecessary_any,
37863788
constraintType)
37873789
.fixItRemove({anyStart, anyEnd});
3790+
return constraintType;
37883791
}
37893792

37903793
return ExistentialType::get(constraintType);
@@ -3972,7 +3975,7 @@ class ExistentialTypeVisitor
39723975
// Arbitrary protocol constraints are okay for 'any' types.
39733976
if (isa<ExistentialTypeRepr>(T))
39743977
return false;
3975-
3978+
39763979
visit(T);
39773980
return true;
39783981
}

0 commit comments

Comments
 (0)