Disallow null references in safe code?

Nick Treleaven ntrel-public at yahoo.co.uk
Sun Feb 2 05:18:17 PST 2014


On 01/02/2014 22:05, Adam D. Ruppe wrote:
> On Saturday, 1 February 2014 at 18:58:11 UTC, Andrei Alexandrescu wrote:
>>     Widget w = fetchWidget();
>>     if (w)
>>     {
>>         ... here w is automatically inferred as non-null ...
>>     }
>
> A library solution to this exists already:
>
> Widget wn = fetchWidget();
> if(auto w = wn.checkNull) {
>     // w implicitly converts to NotNull!Widget
> }

I read your recent post about this, it was interesting. But I don't 
think you can disallow this:

     auto cn = checkNull(cast(C)null);
     NotNull!C nn = cn;

obj2 is then null, when it shouldn't be allowed.


More information about the Digitalmars-d mailing list