You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
enumEither <A, B> {
caseleft(A)
caseright(B)
}
funcfoo(_x: Either<Int, Never>) {
switchx {
case .left(leta): print(a)
case .right(letb): print(b) // should warn that this is unreachable
}
}
funcbar(_x: Either<Int, Never>) {
switchx {
case .left(leta): print(a)
// should consider switch to be exhaustive
}
}
Environment
Swift Development Snapshot 2016-08-04
Additional Detail from JIRA
md5: 3527892211bcbd8b2b306ab21047581f
Issue Description:
It might be useful to use uninhabited types in enums, for example:
However, the compiler will not correctly consider the case
failure
as unreachableAn exhaustive switch for GuaranteedResult should only consist of one case:
The text was updated successfully, but these errors were encountered: