This code: ========== module scratch; class C( element_t ) { element_t [] contents; element_t opIndex( int index ) { return contents[ index ]; } element_t opIndexUnary( string op )( int index ) { static if( op == "++" ) { return ++contents[ index ]; } else { static assert( false ); } } } unittest { auto c = new C!int(); c[0]++; } ========== Produces this output: ========== $ dmd -c -unittest scratch.d scratch.d(42): Error: c.opIndex(0) is not an lvalue ========== But if the penultimate line: "c[0]++" is replaced by "++c[0]", there is no problem. And finally, if the opIndex is changed to return a 'ref', there is not problem, but the opIndexUnary operator is not called - the reference is incremented as an int, I think.
*** Issue 7733 has been marked as a duplicate of this issue. ***
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17518 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB