www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19441] New: alias this causes partial assignment

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

          Issue ID: 19441
           Summary: alias this causes partial assignment
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: eyal weka.io

Reproducing example:

struct S1 {
    int a;
    long b;
    alias a this;
}

struct S2 {
    S1 v;
    alias v this;
}

unittest {
    import std.stdio;
    auto x = S2(S1(1, 12345678));
    writeln(x.a, " ", x.b); // prints: 1 12345678
    S1 y;
    y = x;
    writeln(y.a, " ", y.b); // prints: 1 0
    y = x.v;
    writeln(y.a, " ", y.b); // prints: 1 12345678
}

I think the LHS of assignment should probably not respect `alias this` at all,
as assignment is expected to replace the whole value. If it does, it should go
thru as few alias-this's as possible.

--
Nov 28 2018