Thinking about nothing: Solving the weirdness of the `void` type
Timon Gehr
timon.gehr at gmx.ch
Thu Jul 13 18:56:06 UTC 2023
On 7/13/23 19:58, Quirin Schroll wrote:
> **Key idea: Make `void` an alias to `typeof(null)` when used as a return
> type, with the goal of deprecating `void` return types altogether.**
>
> If this works, we have a three-step plan to transition the language into
> a state in which `void` has a clear meaning: It is the invalid type, the
> not-a-type type as in the not-a-number floating-point number.
>
> Another neat thing about this, the following steps are not needed for
> the previous ones to make sense.
> ...
Some issues with that:
1. deprecation of language features has been deprecated
2. `void` is compatible with C and everyone has built muscle memory for
typing it. Also, it is true that `void[]` is semantically completely
unrelated to `void`, but it's still a special case of `T[]` for `T=void`.
3. `typeof(null)` is not a canonical unit type. It has a subtyping
relationship with class references and pointers. This means you would
sometimes actually need to reserve a full machine word for passing a
`typeof(null)` across a virtual function boundary, while ideally a unit
type can be passed without any dedicated code being executed.
```d
class C{
void foo(typeof(null) x){}
}
class D:C{
void foo(C c){}
}
```
There's probably more issues, this is just off the top of my head.
More information about the Digitalmars-d
mailing list