Bug 21878 – "ref" lost when indexing array in CTFE
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-04-29T17:36:17Z
Last change time
2021-04-30T04:28:03Z
Keywords
CTFE, pull
Assigned to
No Owner
Creator
Vladimir Panteleev
Comments
Comment #0 by dlang-bugzilla — 2021-04-29T17:36:17Z
///////////////////////////////// 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.
Comment #1 by dlang-bugzilla — 2021-04-29T17:39:39Z
I should add that `inout` is also somehow to blame. Works fine without it.
Comment #2 by dlang-bot — 2021-04-30T03:26:59Z
@BorisCarvajal created dlang/dmd pull request #12487 "Fix Issue 21878 - "ref" lost when indexing array in CTFE" fixing this issue:
- Fix Issue 21878 - "ref" lost when indexing array in CTFE
https://github.com/dlang/dmd/pull/12487
Comment #3 by dlang-bot — 2021-04-30T04:28:03Z
dlang/dmd pull request #12487 "Fix Issue 21878 - "ref" lost when indexing array in CTFE" was merged into master:
- 8cd0a729c724eb7d85ed853b064982ae61f19adf by Boris Carvajal:
Fix Issue 21878 - "ref" lost when indexing array in CTFE
https://github.com/dlang/dmd/pull/12487