[swift-evolution] [Draft] Change @noreturn to unconstructible return type
Pyry Jahkola
pyry.jahkola at iki.fi
Sun Jun 5 14:47:26 CDT 2016
>>> 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.
FWIW, in the rejection of SE-0097 <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160530/019879.html>, this was what the core team had to say about it:
1) For noreturn, the core team prefers to explore a solution where a function can be declared as returning an non-constructable “bottom” type (e.g. an enum with zero cases). This would lead to something like:
func abort() -> NoReturn { … }
This will require some new support in the compiler, but should flow better through the type system than @noreturn in function composition and other applications. Joe Groff offered to write a proposal for this.
— Pyry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160605/0a292d24/attachment.html>
More information about the swift-evolution
mailing list