www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2929] New: Alias this when this is null


           Summary: Alias this when this is null
           Product: D
           Version: 2.029
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: jason.james.house gmail.com

The code below should demonstrate the problem.  The implicit use of alias this
is not null-aware.  That means that a nullable class reference with alias this
to another reference type is used, then segfaults will occur.  The only
workaround is to define an intermediate variable and test for null before
relying on the implicit alias to work.  This kind of kills the utility of alias

class A{}
class B{
  private A a;
  A foo(){ return a; }
  alias foo this;

void main(){
  B b;
  A a = b; // seg fault
  assert(a is null);

May 03 2009