Unexpectedly nice case of auto return type
jared771 at gmail.com
Tue Dec 3 22:11:39 UTC 2019
On Tuesday, 3 December 2019 at 17:45:27 UTC, H. S. Teoh wrote:
> The thing is, `void` means "no return type" (or "no type" in
> some contexts), i.e., void == TBottom in that case.
Not *quite* correct. void is not a bottom type; it's a unit type,
meaning that it's a type with only 1 value (as is null,
interestingly). void does not mean "no return type"; it means
"there's only 1 possible value that can be returned". A function
returning TBottom means that the function will never return,
e.g., it loops forever, or throws an exception, etc.
I agree with the OP that it's silly not to give typeof(null) a
name. As null is a unit type, we could easily have `null` stand
in for typeof(null) as well. A type that contains only one value
can be synonymous with that value (see also, Rust's unit type (),
which has one value, ()).
More information about the Digitalmars-d-learn