www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19389] New: Multiple assignment does not work for struct

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

          Issue ID: 19389
           Summary: Multiple assignment does not work for struct members
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: kytodragon e.mail.de

struct Foo {
    int x;

    this(int dummy) {
        x = dummy;
    }
}

struct Bar {
    Foo a;
    Foo b;

    this(int dummy) {
        a = (b = Foo(dummy));
    }
}

void main() {
    Foo a;
    Foo b;
    a = (b = Foo(7));
    assert(b.x == 7 && a.x == 7); // works
    Bar bar = Bar(7);
    assert(bar.b.x == 7 && bar.a.x == 7); // !!! fails, bar.b.x is 0 !!!
}

This was discovered in LDC 1.12.0 and confirmed broken in DMD 2.082.0 .
According to run.dlang.io, this has worked from v2.060 to 2.069, and fails
since 2.070.

--
Nov 10 2018