[ConstraintSystem] Solve where clauses of for-in loops separately

Doing so fits better into conjunction model which leads to more
granular control over what variables are brought into scope during
`where` clause expression checking.

These changes also remove "one-way bind" flag from "for-in" statement
target.
This commit is contained in:
Pavel Yaskevich
2023-09-26 18:03:00 -07:00
parent 8edf870e4b
commit 72caaa8cfe
5 changed files with 30 additions and 20 deletions

View File

@@ -631,7 +631,7 @@ private:
void visitForEachPattern(Pattern *pattern, ForEachStmt *forEachStmt) {
auto target = SyntacticElementTarget::forForEachStmt(
forEachStmt, context.getAsDeclContext(),
/*bindTypeVarsOneWay=*/false);
/*ignoreWhereClause=*/true);
if (cs.generateConstraints(target)) {
hadError = true;
@@ -959,6 +959,20 @@ private:
// they would be handled together with pattern because pattern can
// inform a type of sequence element e.g. `for i: Int8 in 0 ..< 8`
elements.push_back(makeElement(forEachStmt->getPattern(), stmtLoc));
// Where clause if any.
if (auto *where = forEachStmt->getWhere()) {
Type boolType = cs.getASTContext().getBoolType();
if (!boolType) {
hadError = true;
return;
}
ContextualTypeInfo context(boolType, CTP_Condition);
elements.push_back(
makeElement(where, stmtLoc, context, /*isDiscarded=*/false));
}
// Body of the `for-in` loop.
elements.push_back(makeElement(forEachStmt->getBody(), stmtLoc));