digitalmars.D.bugs - [Issue 5123] New: Cannot assign null to a class with 'alias this'
- d-bugmail puremagic.com (31/31) Oct 26 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5123
- d-bugmail puremagic.com (25/25) Oct 26 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5123
- d-bugmail puremagic.com (29/33) Oct 26 2010 This is expected. 'a' is an uninitialized, and attempt to assign to a Fo...
- d-bugmail puremagic.com (7/12) Oct 26 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5123
- d-bugmail puremagic.com (12/12) Oct 23 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5123
http://d.puremagic.com/issues/show_bug.cgi?id=5123 Summary: Cannot assign null to a class with 'alias this' Product: D Version: D2 Platform: Other OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: osa8aso gmail.com If class has 'alias this' for a struct member, attempt to assign null to a class instance fails: ------ struct Foo {} class Bar { Foo foo_; alias foo_ this; } void main() { Bar a; a = null; } ------ aliasthis1.d(8): Error: cannot implicitly convert expression (null) of type void* to Foo -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 26 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5123 bearophile_hugs eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bearophile_hugs eml.cc Here alias this is doing its work of "let's pretend" a Bar instance is a Foo instance. To solve this problem you may need something more refined than alias this, something that allows a partial aliasing. I don't think it's an easy thing to do. A related program shows a different outcome: struct Foo {} class Bar { Foo foo_; alias foo_ this; } void main() { Bar a; //a = null; Foo f; a = f; // Access violation! } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 26 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5123A 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: -------
Oct 26 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5123This 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();Right, sorry for the noise. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 26 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5123 Kenji Hara <k.hara.pg gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED This issue was already fixed by bug 2943. And this was related to bug 6630. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 23 2011