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

H. S. Teoh hsteoh at
Mon Jan 17 02:39:15 UTC 2022

On Mon, Jan 17, 2022 at 12:32:37AM +0000, Paul Backus via Digitalmars-d wrote:
> Unit type = size 0, 1 possible value.
> Bottom type = size 0, 0 possible values.
> The reason there are 0 possible values is because it is the bottom
> type, not because its size is 0.

> On Sunday, 16 January 2022 at 22:56:44 UTC, Max Samukha wrote:
> > I think it depends on the definition of local declaration. For
> > statics, it is obviously a compile-time error. For locals, my
> > feeling is it should be a runtime error, but who knows. Timon,
> > help.
> It would be a compile-time error for essentially the same reason that
> default-initializing a type with a @disabled default constructor is a
> compile-time error: you have asked the compiler to do something that
> it knows, at compile time, is impossible to do.

In this case, the bottom type not only has a @disabled default ctor, it
*cannot* have any ctors (because it has no values). It can never be

> I think maybe the misconception that is leading you astray here is
> that you assume that "default-initializing a variable of type `T`"
> requires "evaluating the expression `T.init`". It does not. What
> default-initializing a variable of type `T` requires is
> 1. Determining the in-memory representation of `T`'s default value.
> 2. Arranging for that representation to be placed in the variable's
> memory at the start of its lifetime.

IMO this is conflating the implementation of default initialization and
the conceptual semantics of declaring a variable at the language level.
In my mind, a variable of some type T is box that stores values of type
T. A variable declaration without an initializer is simply a box that
holds the default value of T.  Since noreturn has no values, it also
doesn't have a default value, so such a box cannot exist. A box that
holds something that cannot exist is a contradiction; i.e., declaring a
variable of type noreturn is a logic error that should either cause a
compilation error or abort at runtime.

> In the case of `noreturn`, the in-memory representation is "nothing",
> because `noreturn` has no default value (nor any other values), and
> arranging for that representation to be placed in the appropriate
> memory is either impossible or a no-op (depending on how you view
> things), because there is nothing to place and no memory to place it
> in.

The in-memory representation doesn't exist, because noreturn has no
values. This is different from something that has a zero-size
representation (i.e., a unit type). It's a contradiction to be in a
situation where such a representation is needed (regardless of its
size), because it can't exist.  So IMO it should be impossible.


Век живи - век учись. А дураком помрёшь.

More information about the Digitalmars-d mailing list