[swift-evolution] [Draft] Change @noreturn to unconstructible return type

Xiaodi Wu xiaodi.wu at gmail.com
Tue Jun 7 15:56:24 CDT 2016

On Tue, Jun 7, 2016 at 3:36 PM, Charles Srstka <cocoadev at charlessoft.com>

> On Jun 7, 2016, at 3:12 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
> On Tue, Jun 7, 2016 at 2:49 PM, Michael Peternell via swift-evolution <
> swift-evolution at swift.org> wrote:
>> > Am 07.06.2016 um 19:45 schrieb Charles Srstka via swift-evolution <
>> swift-evolution at swift.org>:
>> >
>> >> On Jun 7, 2016, at 11:47 AM, Brent Royal-Gordon via swift-evolution <
>> swift-evolution at swift.org> wrote:
>> >>
>> >>> I disagree. We are discussing how to annotate a function in some way
>> so that the compiler knows that the code following it will never be
>> executed *and* so a human who reads the declaration knows that it does not
>> return. “Never" is a poor choice for that. Never what? Never return? Never
>> use this function? Never say never again?
>> >>
>> >> "Never return". That's why it's in the return type slot, right after
>> the `->`. If you read it out loud, you'll read "returns Never", which is
>> exactly correct.
>> >>
>> >> NoReturn, on the other hand, does *not* read well in that slot:
>> "returns NoReturn". Huh? I mean, I suppose you won't misunderstand it, but
>> it makes no sense whatsoever *as a type name*.
>> >
>> > But it’s *not* a type. You’ll never have an instance of it.
> That's the dictionary definition of a bottom type
> <https://en.wikipedia.org/wiki/Bottom_type>, though: a type which has no
> values.
>> Since it’s not a type name, it doesn’t make sense that it needs to look
>> like one. What it is doing is telling you something about the behavior of
>> the function itself, not its return value. Its return value, if there were
>> one, is irrelevant, since the function, by its very nature, will never even
>> get to the point where it would return it.
> And that's the dictionary definition of a function where the return type
> is bottom. This isn't something being made up just for Swift...
> What’s the dictionary definition of a do loop? Or a for loop? Or try/catch?
> Swift doesn’t do things the same as other languages in lots of places. I
> don’t see why it has to be different here. @noreturn is a clearer
> description of what this construct does.

My response was simply to say that Never or NoReturn would in fact be a
type, which is a good justification for looking like one. This behavior
would be learnable and is theoretically sound, not an ad hoc idea being
made up on the spot. No doubt, @noreturn is clearer today, but how much of
that is because it's what we already know? And FWIW, "returns never" is
hard to misinterpret, no?

> Charles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160607/db4a6f17/attachment.html>

More information about the swift-evolution mailing list