Non-null objects, the Null Object pattern, and T.init
Timon Gehr
timon.gehr at gmx.ch
Sun Jan 19 12:07:40 PST 2014
On 01/19/2014 01:03 PM, Michel Fortin wrote:
> Actually, 'A?' would implicitly convert to 'A' where the compiler can
> prove control flow prevents its value from being null.
I think the type should be upgraded. i.e.:
> So you can
> dereference it in a branch that checked for null:
>
> class A { int i; void foo(); }
> void bar(A a); // non-nullable parameter
>
> void test(A? a, A? a2)
> {
> a.i++; // error, 'a' might be null
> a.foo(); // error, 'a' might be null
> bar(a); // error, 'a' might be null
>
> if (a)
> {
static assert(is(typeof(a)==A));
> a.i++; // valid [...]
> a.foo(); // valid [...]
> bar(a); // valid [...]
> }
> }
More information about the Digitalmars-d
mailing list