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

Paul Backus snarwin at
Sat Jan 15 18:35:02 UTC 2022

On Saturday, 15 January 2022 at 17:57:02 UTC, Max Samukha wrote:
> On Saturday, 15 January 2022 at 16:55:49 UTC, Paul Backus wrote:
>> It can't. There are no values of type `noreturn`. The set of 
>> all `noreturn` values is the empty set. That is literally the 
>> definition of a bottom type.
> Right, but if we want to strictly follow the definitions, then 
> we can't declare a variable of the empty type, because the 
> definition of a variable is literally a name associated with a 
> value, so we are back to where we started.

Technically, a variable is a name associated with a block of 
memory, which may or may not contain a value. In the case of 
`noreturn`, the block of memory has size 0, and there are no 
possible values it can contain.

So, technically, a `noreturn` variable is impossible to 
initialize. But since the compiler knows that the behavior of the 
program can't possibly depend on the variable's value, it is free 
to just skip the initialization altogether and leave the variable 
uninitialized instead.

I guess you could make an argument that you should have to write 
`noreturn x = void;` every time you declare a `noreturn` 
variable. But even then, it would not be correct for `noreturn 
x;` to result in an `assert(0)` at runtime--it would have to be a 
*compile-time* error.

More information about the Digitalmars-d mailing list