Unexpectedly nice case of auto return type

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Dec 3 17:45:27 UTC 2019

On Tue, Dec 03, 2019 at 03:19:02AM -0700, Jonathan M Davis via Digitalmars-d-learn wrote:
> On Tuesday, December 3, 2019 3:03:22 AM MST Basile B. via Digitalmars-d-
> learn wrote:
> > [...] maybe we should be able to name the type of null. I think this
> > relates to TBottom too a bit.
> There isn't much point in giving the type of null an explicit name
> given that it doesn't come up very often, and typeof(null) is quite
> explicit about what the type is.

Just add this line somewhere in object.d and we're good to go:

	alias Null = typeof(null);


> As for TBottom, while the DIP does give it a relationship to null,
> they're still separate things, and giving typeof(null) a name wouldn't
> affect TBottom at all.

We need to tread carefully here, because of the unfortunate conflation
of top and bottom types we inherited from C in the form of the keyword
`void`, which greatly confuses the issue.

The thing is, `void` means "no return type" (or "no type" in some
contexts), i.e., void == TBottom in that case.  However, `void*` does
NOT mean a pointer to TBottom; rather, it's a *top type* that includes
pointers of every kind (this can be seen in the fact that any pointer
implicitly converts to void*).

I.e., the relationship between `void` and `void*` is NOT the same as the
relationship with `T` and `T*` for any other T.

This unfortunate overloading of `void` to mean both top and bottom types
in different contexts misleads many C (and D) programmers into the wrong
understanding of what a bottom type is (or what a top type is), and how
it should behave.


The problem with the world is that everybody else is stupid.

More information about the Digitalmars-d-learn mailing list