Bug 14624 – The array operator overloading fallback is not correct
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-05-28T02:49:00Z
Last change time
2015-08-29T09:32:46Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2015-05-28T02:49:18Z
Test case:
struct A1
{
int x;
ref int opIndex() { return x; }
ref int opSlice() { assert(0); }
}
void main()
{
A1 a = A1(1);
auto x = a[]; // a.opIndex(), OK
assert(x == a.x);
// When a.opIndexUnary!"-" is not found,
// it should be rewritten to: -a.opIndex() rather than -a.opSlice()
auto y = -a[]; // asserts in opSlice(), NG
assert(y == -a.x);
// When a.opIndexAssign(int) is not found,
// it should be rewritten to: a.opIndex() = 1; rather than a.opSlice() = 1;
a[] = 1; // asserts in opSlice(), NG
assert(a.x == 1);
// When a.opIndexOpAssign!"+"(int) is not found,
// it should be rewritten to: a.opIndex() += 1; rather than a.opSlice() += 1;
a[] += 1; // asserts in opSlice(), NG
assert(a.x == 2);
}
I caught the issue in the d.learn forum thread that was posted a half year ago:
http://forum.dlang.org/post/[email protected]