Skip to content

Commit 96993e6

Browse files
authored
Merge pull request #16397 from DougGregor/sr-7567-4.2-04-30-2018
[4.2] [Parser] Don't lose outer "disabled" variables when checking a guard's "else"
2 parents 2d8b834 + 20b1f5e commit 96993e6

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
@@ -1605,7 +1605,7 @@ ParserResult<Stmt> Parser::parseStmtGuard() {
16051605
for (auto &elt : Condition)
16061606
if (auto pattern = elt.getPatternOrNull())
16071607
pattern->collectVariables(Vars);
1608-
1608+
Vars.append(DisabledVars.begin(), DisabledVars.end());
16091609
llvm::SaveAndRestore<decltype(DisabledVars)>
16101610
RestoreCurVars(DisabledVars, Vars);
16111611

test/stmt/statements.swift

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

379379

380380
guard case _ = x else {} // expected-warning {{'guard' condition is always true, body is unreachable}}
381+
382+
// SR-7567
383+
guard let outer = y else {
384+
guard true else {
385+
print(outer) // expected-error {{variable declared in 'guard' condition is not usable in its body}}
386+
}
387+
}
381388
}
382389

383390
func test_is_as_patterns() {

0 commit comments

Comments
 (0)