Skip to content

Commit 8b8ccb4

Browse files
committed
[ConstraintSystem] Cache types of ~= components
While synthesizing `~=` application for multi-statement closures or result builder, solver shouldn't set types directly to newly created AST nodes because they might not be fully resolved, instead such types have to be recorded in the constraint system and then set during solution application. Resolves: rdar://91145060.
1 parent 19ebc9b commit 8b8ccb4

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8774,7 +8774,7 @@ ExprWalker::rewriteTarget(SolutionApplicationTarget target) {
87748774
if (auto *enumElement = dyn_cast<EnumElementPattern>(info.pattern)) {
87758775
if (auto target = cs.getSolutionApplicationTarget(enumElement)) {
87768776
auto *EP = target->getExprPattern();
8777-
auto enumType = solution.simplifyType(EP->getType());
8777+
auto enumType = solution.getResolvedType(EP);
87788778

87798779
auto *matchCall = target->getAsExpr();
87808780

lib/Sema/CSSimplify.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8940,6 +8940,9 @@ static bool inferEnumMemberThroughTildeEqualsOperator(
89408940

89418941
std::tie(matchVar, matchCall) = *tildeEqualsApplication;
89428942

8943+
cs.setType(matchVar, enumTy);
8944+
cs.setType(EP, enumTy);
8945+
89438946
// result of ~= operator is always a `Bool`.
89448947
auto target = SolutionApplicationTarget::forExprPattern(
89458948
matchCall, DC, EP, ctx.getBoolDecl()->getDeclaredInterfaceType());
@@ -8968,7 +8971,6 @@ static bool inferEnumMemberThroughTildeEqualsOperator(
89688971
// Store the $match variable and binary expression for solution application.
89698972
EP->setMatchVar(matchVar);
89708973
EP->setMatchExpr(matchCall);
8971-
EP->setType(enumTy);
89728974

89738975
cs.setSolutionApplicationTarget(pattern, target);
89748976

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,8 @@ bool TypeChecker::typeCheckExprPattern(ExprPattern *EP, DeclContext *DC,
880880

881881
std::tie(matchVar, matchCall) = *tildeEqualsApplication;
882882

883+
matchVar->setInterfaceType(rhsType->mapTypeOutOfContext());
884+
883885
// Result of `~=` should always be a boolean.
884886
auto contextualTy = Context.getBoolDecl()->getDeclaredInterfaceType();
885887
auto target = SolutionApplicationTarget::forExprPattern(matchCall, DC, EP,
@@ -908,7 +910,6 @@ TypeChecker::synthesizeTildeEqualsOperatorApplication(ExprPattern *EP,
908910
auto *matchVar =
909911
new (Context) VarDecl(/*IsStatic*/ false, VarDecl::Introducer::Let,
910912
EP->getLoc(), Context.Id_PatternMatchVar, DC);
911-
matchVar->setInterfaceType(enumType->mapTypeOutOfContext());
912913

913914
matchVar->setImplicit();
914915

0 commit comments

Comments
 (0)