Skip to content

Commit 5fa72f5

Browse files
authored
Merge pull request #16388 from DougGregor/sr-7567
2 parents dd17ca0 + 1ac8926 commit 5fa72f5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/Parse/ParseStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ ParserResult<Stmt> Parser::parseStmtGuard() {
16121612
for (auto &elt : Condition)
16131613
if (auto pattern = elt.getPatternOrNull())
16141614
pattern->collectVariables(Vars);
1615-
1615+
Vars.append(DisabledVars.begin(), DisabledVars.end());
16161616
llvm::SaveAndRestore<decltype(DisabledVars)>
16171617
RestoreCurVars(DisabledVars, Vars);
16181618

test/stmt/statements.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@ func test_guard(_ x : Int, y : Int??, cond : Bool) {
383383

384384

385385
guard case _ = x else {} // expected-warning {{'guard' condition is always true, body is unreachable}}
386+
387+
// SR-7567
388+
guard let outer = y else {
389+
guard true else {
390+
print(outer) // expected-error {{variable declared in 'guard' condition is not usable in its body}}
391+
}
392+
}
386393
}
387394

388395
func test_is_as_patterns() {

0 commit comments

Comments
 (0)