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

           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: bugzi...@digitalmars.com
        ReportedBy: jason.james.ho...@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
this.

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);
}


-- 

Reply via email to