Skip to content

Commit 9c4ff93

Browse files
committed
[TypeChecker] Switch typeCheckExprPattern to use expr pattern target
1 parent 4ba8d4c commit 9c4ff93

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,13 +672,22 @@ bool TypeChecker::typeCheckExprPattern(ExprPattern *EP, DeclContext *DC,
672672
/*Implicit=*/true);
673673
Expr *matchCall = BinaryExpr::create(Context, EP->getSubExpr(), matchOp,
674674
matchVarRef, /*implicit*/ true);
675+
676+
// Result of `~=` should always be a boolean.
677+
auto contextualTy = Context.getBoolDecl()->getDeclaredInterfaceType();
678+
auto target = SolutionApplicationTarget::forExprPattern(matchCall, DC, EP,
679+
contextualTy);
680+
675681
// Check the expression as a condition.
676-
bool hadError = typeCheckCondition(matchCall, DC);
682+
auto result = typeCheckExpression(target);
683+
if (!result)
684+
return true;
685+
677686
// Save the type-checked expression in the pattern.
678-
EP->setMatchExpr(matchCall);
687+
EP->setMatchExpr(result->getAsExpr());
679688
// Set the type on the pattern.
680689
EP->setType(rhsType);
681-
return hadError;
690+
return false;
682691
}
683692

684693
static Type replaceArchetypesWithTypeVariables(ConstraintSystem &cs,

0 commit comments

Comments
 (0)