www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20917] New: stacking alias this, drops data during assignment

https://issues.dlang.org/show_bug.cgi?id=20917

          Issue ID: 20917
           Summary: stacking alias this, drops data during assignment
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: crazymonkyyy gmail.com

struct ihatecompilers(T,size_t n){
  struct hate{
    T payload; alias payload this;
    float depthofhatred=float.max;
  }
  hate data;
  void opAssign(T a){
    data=a;
    import std.stdio;
    data.writeln;
    assert(data==a);
  }
}
unittest{
  struct inner{int a;}
  struct outer{
    inner payload;alias payload this;
    string metadata;
  }
  ihatecompilers!(outer,100) foo;
  inner bar= inner(10);
  foo=outer(bar,"very very very important data");
}

foo is assigned as outer(inner(10),""), droping the very very important data

--
Jun 09