Null references redux

Jeremie Pelletier jeremiep at gmail.com
Tue Sep 29 14:43:25 PDT 2009


Rainer Deyke wrote:
> Jeremie Pelletier wrote:
>> struct NonNull(C) if(is(C == class)) {
>>     C ref;
>>     invariant() { assert(ref !is null); }
>>     T opDot() { return ref; }
>> }
> 
> This only catches null errors at runtime.  The whole point of a non-null
> type is to catch null errors at compile time.
> 

Thats what flow analysis is for, since these are mostly uninitialized 
variables rather than null ones.

Its dead easy to insert null into a nonnull reference, and since you 
expect the type to never be null its the last thing you're gonna check. 
If variables are properly initialized, you'll never get null where you 
don't expect it, and those are checked at compile time too, and work on 
every type.



More information about the Digitalmars-d mailing list