[Issue 14624] New: The array operator overloading fallback is not correct
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed May 27 19:49:18 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14624
Issue ID: 14624
Summary: The array operator overloading fallback is not correct
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: wrong-code
Severity: normal
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: k.hara.pg at gmail.com
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/luadir$t0g$1@digitalmars.com
--
More information about the Digitalmars-d-bugs
mailing list