Skip to content

Commit a65105c

Browse files
authored
Merge pull request #17529 from rudkx/rdar41305565
[Stmt] Do not crash if we have a switch after a fallthrough.
2 parents a7b4e0f + 465540c commit a65105c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/Sema/TypeCheckStmt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -948,7 +948,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
948948

949949
// If the previous case fellthrough, similarly check that that case's bindings
950950
// includes our first label item's pattern bindings and types.
951-
if (PreviousFallthrough) {
951+
if (PreviousFallthrough && previousBlock) {
952952
auto firstPattern = caseBlock->getCaseLabelItems()[0].getPattern();
953953
SmallVector<VarDecl *, 4> Vars;
954954
firstPattern->collectVariables(Vars);

test/stmt/switch_stmt2.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,17 @@ func non_fully_covered_switch(x: Int) -> Int {
136136
}
137137
return x
138138
}
139+
140+
// Do not crash if another switch statement follows a fallthrough.
141+
func fallthrough_not_last(i: Int) {
142+
switch i {
143+
case 1:
144+
fallthrough
145+
switch i {
146+
case 1: break
147+
default: break
148+
}
149+
default:
150+
break
151+
}
152+
}

0 commit comments

Comments
 (0)