Skip to content

Fix assertion from empty switch over uninhabited enum #19979

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
Oct 29, 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
5 changes: 5 additions & 0 deletions lib/SILGen/SILGenPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions test/Sema/exhaustive_switch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ enum MyNever {}
func ~= (_ : MyNever, _ : MyNever) -> Bool { return true }
func myFatalError() -> MyNever { fatalError() }

@_frozen public enum UninhabitedT4<A> {
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
Expand All @@ -379,6 +383,10 @@ func checkUninhabited() {
case myFatalError(): break
}
}

func test4(x: UninhabitedT4<Never>) {
switch x {} // No diagnostic.
}
}

enum Runcible {
Expand Down