digitalmars.D.bugs - [Issue 14624] New: The array operator overloading fallback is not
- via Digitalmars-d-bugs (43/43) May 27 2015 https://issues.dlang.org/show_bug.cgi?id=14624
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 puremagic.com Reporter: k.hara.pg 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 --
May 27 2015