Skip to content

Commit bf124b8

Browse files
committed
[Type checker] Use typeCheckCondition() rather than fake it.
Type checking an expression pattern had a hack to work around some diagnostics issues with conditions. These issues have been addressed by the new diagnostic infrastructure, so remove this unnecessary use of ExprTypeCheckListener and check the expression pattern condition using… typeCheckCondition().
1 parent ce35731 commit bf124b8

File tree

1 file changed

+1
-24
lines changed

1 file changed

+1
-24
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3209,30 +3209,7 @@ bool TypeChecker::typeCheckExprPattern(ExprPattern *EP, DeclContext *DC,
32093209
/*Implicit=*/true);
32103210

32113211
// Check the expression as a condition.
3212-
//
3213-
// TODO: Type-check of `~=` operator can't (yet) use `typeCheckCondition`
3214-
// because that utilizes contextual type which interferes with diagnostics.
3215-
// We don't yet have a full access to pattern-matching context in
3216-
// constraint system, which is required to enable these situations
3217-
// to be properly diagnosed.
3218-
struct ConditionListener : public ExprTypeCheckListener {
3219-
// Add the appropriate Boolean constraint.
3220-
bool builtConstraints(ConstraintSystem &cs, Expr *expr) override {
3221-
// Otherwise, the result must be convertible to Bool.
3222-
auto boolDecl = cs.getASTContext().getBoolDecl();
3223-
if (!boolDecl)
3224-
return true;
3225-
3226-
// Condition must convert to Bool.
3227-
cs.addConstraint(ConstraintKind::Conversion, cs.getType(expr),
3228-
boolDecl->getDeclaredType(),
3229-
cs.getConstraintLocator(expr));
3230-
return false;
3231-
}
3232-
};
3233-
3234-
ConditionListener listener;
3235-
bool hadError = !typeCheckExpression(matchCall, DC, &listener);
3212+
bool hadError = typeCheckCondition(matchCall, DC);
32363213
// Save the type-checked expression in the pattern.
32373214
EP->setMatchExpr(matchCall);
32383215
// Set the type on the pattern.

0 commit comments

Comments
 (0)