digitalmars.D.bugs - [Issue 21878] New: "ref" lost when indexing array in CTFE
- d-bugmail puremagic.com (43/43) Apr 29 2021 https://issues.dlang.org/show_bug.cgi?id=21878
https://issues.dlang.org/show_bug.cgi?id=21878 Issue ID: 21878 Summary: "ref" lost when indexing array in CTFE Product: D Version: D2 Hardware: All OS: All Status: NEW Keywords: CTFE Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: dlang-bugzilla thecybershadow.net ///////////////////////////////// test.d //////////////////////////////// struct A { int i; ref inout(int) opIndex(size_t idx) inout return { return i; } } struct B { A[1] a; ref inout(int) opIndex(size_t idx) inout return { return a[0][idx]; } } bool ctfeFunc() { A a; a[0] = 42; assert(a[0] == 42); // OK B b; b[0] = 42; assert(b[0] == 42); // fails return true; } enum eval = ctfeFunc(); unittest { ctfeFunc(); // succeeds at runtime } ///////////////////////////////////////////////////////////////////////// It looks like the assignment is going into some rvalue which is then lost. --
Apr 29 2021