int test(int x) { return -- -x; // error: -x is not an lvalue return -- - --x; // error: -(x -= 1) is not an lvalue return -- - -- --x; // error: -((x -= 1 , x) -= 1) is not an lvalue return -- - -- -- --x; // error: -((ref int __assignop1 = x -= 1 , __assignop1 = x; , __assignop1 -= 1 , __assignop1) -= 1) is not an lvalue }
Of course, this is a pathological case, but artificial names should never be exposed in compiler errors.
PR https://github.com/D-Programming-Language/dmd/pull/4415 will improve the diagnostic to: test.d(3): Error: -x is not an lvalue test.d(4): Error: -(x -= 1) is not an lvalue test.d(5): Error: -(x -= 1 -= 1) is not an lvalue test.d(6): Error: -(x -= 1 -= 1 -= 1) is not an lvalue It's not perfect, but far better.
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/bf3cb7bf5d3f735cebe07757e4d03c88b76d00d4 A little diagnostic improvement for issue 14102
Commit pushed to https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/bf3cb7bf5d3f735cebe07757e4d03c88b76d00d4 A little diagnostic improvement for issue 14102
I now get: test.d(3): Error: `-x` is not an lvalue and cannot be modified test.d(4): Error: `-(x -= 1)` is not an lvalue and cannot be modified test.d(5): Error: `-(x -= 1 -= 1)` is not an lvalue and cannot be modified test.d(6): Error: `-(x -= 1 -= 1 -= 1)` is not an lvalue and cannot be modified Looks fine to me. Closing as WORKSFORME. @Iain, is this what you were expecting?