[swift-evolution] Idea: change "@noreturn func f()" to "func f() noreturn"

Joe Groff jgroff at apple.com
Fri Feb 26 11:46:58 CST 2016


> On Feb 25, 2016, at 11:39 PM, Jean-Daniel Dupas <mailing at xenonium.com> wrote:
> 
> 
>> Le 25 févr. 2016 à 23:40, Joe Groff via swift-evolution <swift-evolution at swift.org> a écrit :
>> 
>> 
>>> On Feb 25, 2016, at 2:40 PM, Radosław Pietruszewski <radexpl at gmail.com> wrote:
>>> 
>>> Ah, that’s a neat idea! Not sure it’s an improvement though to have a magic type that changes how the compiler treats your method, rather than a rather explicit *attribute* on the method…
>> 
>> There's no magic. If you can't construct a value of your return type, you can't return.
> 
> Just curious about how you would implement such function if there is no compile magic ?
> 
> How do you tell the compiler is it not an error that your function never return while it is declared to return something ?

The compiler can tell statically that a closed, empty enum type is uninhabited, and thereby figure out that it's impossible for a function returning an uninhabited type can't possibly return.

-Joe



More information about the swift-evolution mailing list