Non-null objects, the Null Object pattern, and T.init

Jacob Carlborg doob at me.com
Fri Jan 17 00:13:29 PST 2014


On 2014-01-17 07:18, Timon Gehr wrote:

> class Foo{ int x = 2; }
>
> class Bar{ auto foo = new Foo(); }
>
> void main(){
>      auto ibar = new immutable(Bar)();
>      auto bar = new Bar();
>      static assert(is(typeof(ibar.foo.x)==immutable));
>      assert(ibar.foo.x==2);
>      bar.foo.x=3;
>      assert(ibar.foo.x==3); // uh-oh!
> }

Oh, that's just bad. Yet another hole in the type system.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list