[Issue 5123] Cannot assign null to a class with 'alias this'

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 26 15:17:53 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=5123



--- Comment #2 from osa8aso at gmail.com 2010-10-26 15:17:04 PDT ---
> A related program shows a different outcome:
>     Bar a;
>     Foo f;
>     a = f; // Access violation!

This is expected. 'a' is an uninitialized, and attempt to assign to a Foo part
of null instance causes access violation. This is no different from

  Bar a;
  a.foo_ = Foo();

"Partial" assignment of Foo to a valid Bar instance is fine and works as
expected:
-----
struct Foo { int x; }
class Bar {
    Foo foo_;
    alias foo_ this;
    int y;
}
void main() {
    Bar a = new Bar;
    a.x = 1;
    a.y = 42;
    assert( a.foo_.x == 1 && a.y == 42 );
    a = Foo( 2 );
    assert( a.foo_.x == 2 && a.y == 42 );
}
-----

My problem is only with special treatment of null: I want to nullify local
reference to a Bar instance, not change Bar or Foo inside it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list