Skip to content

Commit 5a66b62

Browse files
authored
Merge pull request #69304 from xedin/rdar-117220710
[ConstraintSystem] Bring back one-way pattern solving for for-in stat…
2 parents 36824b5 + b405cee commit 5a66b62

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

include/swift/Sema/SyntacticElementTarget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ class SyntacticElementTarget {
469469
bool shouldBindPatternVarsOneWay() const {
470470
if (kind == Kind::expression)
471471
return expression.bindPatternVarsOneWay;
472+
if (kind == Kind::forEachStmt)
473+
return !ignoreForEachWhereClause() && forEachStmt.stmt->getWhere();
472474
return false;
473475
}
474476

test/stmt/foreach.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,24 @@ do {
295295
}
296296
}
297297
}
298+
299+
// rdar://117220710 - The compiler incorrectly infers `v` pattern to be optional.
300+
do {
301+
struct S {
302+
var test: Int
303+
}
304+
305+
func check(_: S?, _: S?) -> Bool { false }
306+
307+
func test(data: [S]?, exclusion: S?) {
308+
for v in data ?? [] where check(v, exclusion) {
309+
_ = v.test // Ok
310+
}
311+
}
312+
313+
let _ = { (data: [S]?, exclusion: S?) in
314+
for v in data ?? [] where check(v, exclusion) {
315+
_ = v.test // Ok
316+
}
317+
}
318+
}

0 commit comments

Comments
 (0)