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]
Comment #1 by k.hara.pg — 2015-05-28T15:13:03Z
Comment #2 by k.hara.pg — 2015-08-20T21:43:16Z
*** Issue 14941 has been marked as a duplicate of this issue. ***
Comment #3 by code — 2015-08-29T05:26:15Z
Why would we support an argument-less opIndex?
Comment #4 by code — 2015-08-29T05:41:16Z
I see it was introduced with multi-dimensional slicing support. http://dlang.org/operatoroverloading#slice
Comment #5 by github-bugzilla — 2015-08-29T07:40:30Z
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/bfb7f8d2a116578a57be29d87da3db010b565bb1 fix Issue 14624 - The array operator overloading fallback is not correct https://github.com/D-Programming-Language/dmd/commit/d99699301eb0f5d46b4f9240236ca7c1694bb39b Merge pull request #4948 from 9rnsr/fix14621 Issue 14621, 14624, 14625 - Fix bugs in array operator overloading semantics
Comment #6 by github-bugzilla — 2015-08-29T09:32:46Z