Merge pull request #69304 from xedin/rdar-117220710

[ConstraintSystem] Bring back one-way pattern solving for for-in stat…
This commit is contained in:
Pavel Yaskevich
2023-10-25 09:43:33 -07:00
committed by GitHub
2 changed files with 23 additions and 0 deletions

View File

@@ -469,6 +469,8 @@ public:
bool shouldBindPatternVarsOneWay() const {
if (kind == Kind::expression)
return expression.bindPatternVarsOneWay;
if (kind == Kind::forEachStmt)
return !ignoreForEachWhereClause() && forEachStmt.stmt->getWhere();
return false;
}

View File

@@ -295,3 +295,24 @@ do {
}
}
}
// rdar://117220710 - The compiler incorrectly infers `v` pattern to be optional.
do {
struct S {
var test: Int
}
func check(_: S?, _: S?) -> Bool { false }
func test(data: [S]?, exclusion: S?) {
for v in data ?? [] where check(v, exclusion) {
_ = v.test // Ok
}
}
let _ = { (data: [S]?, exclusion: S?) in
for v in data ?? [] where check(v, exclusion) {
_ = v.test // Ok
}
}
}