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
https://github.com/D-Programming-Language/dmd/pull/4686
*** Issue 14941 has been marked as a duplicate of this issue. ***
Why would we support an argument-less opIndex?
I see it was introduced with multi-dimensional slicing support. http://dlang.org/operatoroverloading#slice
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
Commits pushed to master 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