Skip to content

Commit bddc511

Browse files
authored
Merge pull request #59166 from xedin/rdar-94049113-5.7
[5.7][CSClosure] Perform syntactic checks on rewritten statements
2 parents 596c18b + 912d7f1 commit bddc511

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lib/Sema/CSClosure.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,17 @@ class ClosureConstraintApplication
11961196
return nullptr;
11971197
}
11981198

1199+
ASTNode visit(Stmt *S) {
1200+
auto rewritten = ASTVisitor::visit(S);
1201+
if (!rewritten)
1202+
return {};
1203+
1204+
if (auto *stmt = getAsStmt(rewritten))
1205+
performStmtDiagnostics(stmt, closure);
1206+
1207+
return rewritten;
1208+
}
1209+
11991210
void visitDecl(Decl *decl) {
12001211
if (isa<IfConfigDecl>(decl))
12011212
return;

test/expr/closure/multi_statement.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,36 @@ func test_type_finder_doesnt_walk_into_inner_closures() {
405405
}
406406
}
407407

408+
// rdar://94049113 - compiler accepts non-optional `guard let` in a closure
409+
func test_non_optional_guard_let_is_diagnosed() {
410+
func fn(_: (Int) -> Void) {}
411+
412+
fn {
413+
if true {
414+
guard let v = $0 else { // expected-error {{initializer for conditional binding must have Optional type, not 'Int'}}
415+
return
416+
}
417+
418+
print(v)
419+
}
420+
}
421+
422+
fn {
423+
switch $0 {
424+
case (let val):
425+
fn {
426+
guard let x = val else { // expected-error {{initializer for conditional binding must have Optional type, not 'Int'}}
427+
return
428+
}
429+
430+
print($0 + x)
431+
}
432+
433+
default: break
434+
}
435+
}
436+
}
437+
408438
// rdar://93796211 (issue#59035) - crash during solution application to fallthrough statement
409439
func test_fallthrough_stmt() {
410440
{

0 commit comments

Comments
 (0)