bottom type as parameter or local variable, does that make sense?

Timon Gehr timon.gehr at gmx.ch
Fri Jan 14 17:14:17 UTC 2022


On 1/14/22 12:52, WebFreak001 wrote:
> For example:
> ```d
> import std.stdio;
> 
> void foo(noreturn a)
> {
>      writeln("we got called!");
> }
> 
> void bar()
> {
>      noreturn b;
>      writeln("calling");
>      foo(b);
> }
> 
> void main()
> {
>      writeln("bar");
>      bar();
>      writeln("done");
> }
> ```
> 
> Guess what it prints and reply to it on this thread. I think the result 
> is pretty nonsensical.
> 
> Reveal: https://run.dlang.io/is/4SXQal
> 
> Should this usage be allowed? I would say not allowing it would make 
> more sense.

Debatable, but I think you have misidentified the questionable 
construct. I think the only question here is whether `noreturn` should 
have default construction. Maybe not. It should certainly be allowed as 
the type of a parameter or local variable, as avoiding that kind of 
special case is more or less the point of the feature.


More information about the Digitalmars-d mailing list