Skip to content

[4.2][Stmt] Do not crash if we have a switch after a fallthrough. #17530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Sema/TypeCheckStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -948,7 +948,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {

// If the previous case fellthrough, similarly check that that case's bindings
// includes our first label item's pattern bindings and types.
if (PreviousFallthrough) {
if (PreviousFallthrough && previousBlock) {
auto firstPattern = caseBlock->getCaseLabelItems()[0].getPattern();
SmallVector<VarDecl *, 4> Vars;
firstPattern->collectVariables(Vars);
Expand Down
14 changes: 14 additions & 0 deletions test/stmt/switch_stmt2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,17 @@ func non_fully_covered_switch(x: Int) -> Int {
}
return x
}

// Do not crash if another switch statement follows a fallthrough.
func fallthrough_not_last(i: Int) {
switch i {
case 1:
fallthrough
switch i {
case 1: break
default: break
}
default:
break
}
}