Non-nullable references, again

Daniel Keep daniel.keep.lists at gmail.com
Wed Dec 31 09:24:42 PST 2008



Denis Koroskin wrote:
> [snip]
> 
> You took the idea slightly wrong. The default should be non-nullable,
> 
> Foo foo = null; // error
> Nullable!(Foo) foo2 = null; // ok

I didn't suggest that because it would require semantically breaking all 
existing OOP code in D.  I went with a proxy struct idea since that 
could conceivably be implemented in a library, and provide a stepping 
stone to full non-nullable by default.

> [snip]
 >
>> It also just occured to me that this would probably break scope.  Damn.
>>
> 
> Scope is not broken. Quite the contrary, it goes on par with its meaning 
> - scope variable can't be null-initialized (it makes no sense at least).

I was referring to the case of using a proxy struct.

scope NonNull!(Foo) bar = new Foo;

AFAIK, this wouldn't have the desired behaviour (auto-collecting bar at 
the end of scope.)

   -- Daniel



More information about the Digitalmars-d mailing list