Skip to content

Commit d727a79

Browse files
authored
Merge pull request #42146 from xedin/rdar-91145060
[ConstraintSystem] Cache types of `~=` components
2 parents 5ac5411 + 8b8ccb4 commit d727a79

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
@@ -8944,6 +8944,9 @@ static bool inferEnumMemberThroughTildeEqualsOperator(
89448944

89458945
std::tie(matchVar, matchCall) = *tildeEqualsApplication;
89468946

8947+
cs.setType(matchVar, enumTy);
8948+
cs.setType(EP, enumTy);
8949+
89478950
// result of ~= operator is always a `Bool`.
89488951
auto target = SolutionApplicationTarget::forExprPattern(
89498952
matchCall, DC, EP, ctx.getBoolDecl()->getDeclaredInterfaceType());
@@ -8972,7 +8975,6 @@ static bool inferEnumMemberThroughTildeEqualsOperator(
89728975
// Store the $match variable and binary expression for solution application.
89738976
EP->setMatchVar(matchVar);
89748977
EP->setMatchExpr(matchCall);
8975-
EP->setType(enumTy);
89768978

89778979
cs.setSolutionApplicationTarget(pattern, target);
89788980

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)