Skip to content

[SR-2293] Detect enum cases with uninhabited types as unreachable #44900

@swift-ci

Description

@swift-ci
Previous ID SR-2293
Radar None
Original Reporter loic (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Swift Development Snapshot 2016-08-04

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @CodaFi
Priority Medium

md5: 3527892211bcbd8b2b306ab21047581f

Issue Description:

It might be useful to use uninhabited types in enums, for example:

enum NeverError: Error { }
enum Result <T, E: Error> {
    case success(T)
    case failure(E)  
} 
typealias GuaranteedResult<T> = Result<T, NeverError>

However, the compiler will not correctly consider the case failure as unreachable

func foo(result: GuaranteedResult<Int>) {
    switch result {
    case .success(let x): …
    case .failure(let n): … // should warn that this code is unreachable
    }
}

An exhaustive switch for GuaranteedResult should only consist of one case:

switch result {
    case .success(let x): …
}
// switch should be considered exhaustive

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions