diff --git a/lib/SILGen/SILGenPattern.cpp b/lib/SILGen/SILGenPattern.cpp index 8944c4550254e..985c96e9bd967 100644 --- a/lib/SILGen/SILGenPattern.cpp +++ b/lib/SILGen/SILGenPattern.cpp @@ -983,6 +983,11 @@ chooseNecessaryColumn(const ClauseMatrix &matrix, unsigned firstRow) { /// Recursively emit a decision tree from the given pattern matrix. void PatternMatchEmission::emitDispatch(ClauseMatrix &clauses, ArgArray args, const FailureHandler &outerFailure) { + if (clauses.rows() == 0) { + SGF.B.createUnreachable(SILLocation(PatternMatchStmt)); + return; + } + unsigned firstRow = 0; while (true) { // If there are no rows remaining, then we fail. diff --git a/test/Sema/exhaustive_switch.swift b/test/Sema/exhaustive_switch.swift index f9629dd091946..728d13e9c2363 100644 --- a/test/Sema/exhaustive_switch.swift +++ b/test/Sema/exhaustive_switch.swift @@ -360,6 +360,10 @@ enum MyNever {} func ~= (_ : MyNever, _ : MyNever) -> Bool { return true } func myFatalError() -> MyNever { fatalError() } +@_frozen public enum UninhabitedT4 { + case x(A) +} + func checkUninhabited() { // Scrutinees of uninhabited type may match any number and kind of patterns // that Sema is willing to accept at will. After all, it's quite a feat to @@ -379,6 +383,10 @@ func checkUninhabited() { case myFatalError(): break } } + + func test4(x: UninhabitedT4) { + switch x {} // No diagnostic. + } } enum Runcible {