Skip to content

Commit 7b5e83d

Browse files
authored
Merge pull request swiftlang#19979 from mdiep/SR-8933
Fix assertion from empty switch over uninhabited enum
2 parents ab2dd10 + cd2daa9 commit 7b5e83d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/SILGen/SILGenPattern.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,11 @@ chooseNecessaryColumn(const ClauseMatrix &matrix, unsigned firstRow) {
989989
/// Recursively emit a decision tree from the given pattern matrix.
990990
void PatternMatchEmission::emitDispatch(ClauseMatrix &clauses, ArgArray args,
991991
const FailureHandler &outerFailure) {
992+
if (clauses.rows() == 0) {
993+
SGF.B.createUnreachable(SILLocation(PatternMatchStmt));
994+
return;
995+
}
996+
992997
unsigned firstRow = 0;
993998
while (true) {
994999
// If there are no rows remaining, then we fail.

test/Sema/exhaustive_switch.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ enum MyNever {}
360360
func ~= (_ : MyNever, _ : MyNever) -> Bool { return true }
361361
func myFatalError() -> MyNever { fatalError() }
362362

363+
@_frozen public enum UninhabitedT4<A> {
364+
case x(A)
365+
}
366+
363367
func checkUninhabited() {
364368
// Scrutinees of uninhabited type may match any number and kind of patterns
365369
// that Sema is willing to accept at will. After all, it's quite a feat to
@@ -379,6 +383,10 @@ func checkUninhabited() {
379383
case myFatalError(): break
380384
}
381385
}
386+
387+
func test4(x: UninhabitedT4<Never>) {
388+
switch x {} // No diagnostic.
389+
}
382390
}
383391

384392
enum Runcible {

0 commit comments

Comments
 (0)