[swift-evolution] [Draft] Change @noreturn to unconstructible return type
cocoadev at charlessoft.com
Sun Jun 5 13:55:01 CDT 2016
> On Jun 5, 2016, at 1:49 PM, Pyry Jahkola via swift-evolution <swift-evolution at swift.org> wrote:
>> On 05 Jun 2016, at 21:26, Антон Жилин via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> The following names were suggested: NoReturn, Bottom, None, Never.
>> I would pick None, because it looks like opposite to Any and fits nicely in generic types.
> I would pick `Never` because `None` would overload the notion of a returnable nothingness with its antonym!
> OTOH, "never" is quite unlikely to be a type name in user code, likely pretty googleable, and explains itself quite well in examples like `Result<Value, Never>`.
>> I would prefer the type to be simple, and be implemented as a case-less enum (not a bottom value, as in Haskell).
>> None should be a usual enum, with no compiler magic except that functions returning None are equivalent to current @noreturn.
> I think it would be more useful if the compiler allowed `Never` in every type context (i.e. whatever type `T` was expected, an expression of type `Never` would be allowed), making expressions like the following compile:
> let unwrapped: Int = optional ?? fatalError("explanation why this must not happen")
> — Pyry
I dunno, I think @noreturn is clearer than any of these. It tells you that the function… won’t return. None, Never, etc. could be mistaken as a synonym for Void, whereas @noreturn is pretty hard to miss.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution