Skip to content

[4.2] Space Engine: uninhabited types map to empty spaces #17690

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
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
2 changes: 2 additions & 0 deletions lib/Sema/TypeCheckSwitchStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ namespace {
Spaces({}) {}

static Space forType(Type T, Identifier NameForPrinting) {
if (T->isStructurallyUninhabited())
return Space();
return Space(T, NameForPrinting);
}
static Space forUnknown(bool allowedButNotRequired) {
Expand Down
20 changes: 20 additions & 0 deletions test/Compatibility/exhaustive_switch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1184,3 +1184,23 @@ func testUnavailableCases(_ x: UnavailableCase, _ y: UnavailableCaseOSSpecific,
case .notYetIntroduced: break
} // no-error
}

// The following test used to behave differently when the uninhabited enum was
// defined in the same module as the function (as opposed to using Swift.Never).
enum NoError {}
extension Result where T == NoError {
func testUninhabited() {
switch self {
case .Error(_):
break
// No .Ok case possible because of the 'NoError'.
}

switch self {
case .Error(_):
break
case .Ok(_):
break // But it's okay to write one.
}
}
}
20 changes: 20 additions & 0 deletions test/Sema/exhaustive_switch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1223,3 +1223,23 @@ func testUnavailableCases(_ x: UnavailableCase, _ y: UnavailableCaseOSSpecific,
case .notYetIntroduced: break
} // no-error
}

// The following test used to behave differently when the uninhabited enum was
// defined in the same module as the function (as opposed to using Swift.Never).
enum NoError {}
extension Result where T == NoError {
func testUninhabited() {
switch self {
case .Error(_):
break
// No .Ok case possible because of the 'NoError'.
}

switch self {
case .Error(_):
break
case .Ok(_):
break // But it's okay to write one.
}
}
}