null [re: spec#]

Jonathan M Davis jmdavisProg at gmx.com
Mon Nov 8 04:42:15 PST 2010


On Monday 08 November 2010 01:10:07 Simen kjaeraas wrote:
> Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote:
> > On 11/7/10 4:21 PM, bearophile wrote:
> >> Andrei Alexandrescu:
> >>> And what was exactly the claim that was wrong?
> >> 
> >> That there is no need of compiler&  syntax support to implement "good
> >> enough" nonnullable reference types in D.
> > 
> > The only change needed is constructor flow to make sure types with
> > @disable'd constructors are always properly initialized. Array
> > construction can be supported with a library function.
> 
> One more thing: structs with NotNull!T fields will need to have their
> default constructor disabled automagically.

??? Structs have no default constructor. They have an init property with is used 
for default initialization. And if you could enforce that a struct be properly 
initialized rather than default initialized, that would be a big change. 
Granted, I hate the fact that you can't have default constructors on structs, 
that you cannot enforce that a struct be initialized instead of default 
initialized, and that you cannot yet use new in CTFE and therefore have structs 
whose fields which are references be default initialized to null, but as it 
stands, you cannot get around the problem.

Either init needs to be changed to allow for real default constructors and/or 
objects need to be legal CTFE - ideally both. But while the second is supposed 
to happen at some point, there is no sign of it happening any time soon, and 
there appears to be no sign that the first will ever happen. So, there is not 
currently a way to have NotNull!T hold anything but null initially when it's a 
member variable of a struct, and there's no sign of that changing any time soon. 
It is true, however, that the issue must be resolved for NotNull!T to really 
work.

- Jonathan M Davis


More information about the Digitalmars-d mailing list