Null and IFTI
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sun Dec 11 08:00:13 PST 2011
On 12/11/11 6:05 AM, kenji hara wrote:
> 2.057 will compile this code, because it adds the new feature.
> Now null literal has the type that is expressed as typeof(null), not void*.
> And typeof(null) is derived from all class types.
>
> static assert(is(typeof(null) : Bob)); // pass in 2.057
>
> Then IFTI works with null literal correctly.
>
> Kenji Hara
This is theoretically correct and practically elegantly realized. Thanks
Kenji! I love how you got this not-so-obvious aspect right.
The null reference is what's called a "bottom type" in the class type
lattice, i.e. is the opposite of Object, which would be a "top type".
Object is the most general type, the supertype of all classes;
typeof(null) is the most specific type, the subtype of all classes. It
is in fact so specific it can't be instantiated.
Thanks again,
Andrei
More information about the Digitalmars-d
mailing list