Bug 14102 – Bad 'is not an lvalue' diagnostic in chained -unary and --preincr expressions.

Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-02-01T16:06:21Z
Last change time
2022-12-16T13:44:45Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Iain Buclaw

Comments

Comment #0 by ibuclaw — 2015-02-01T16:06:21Z
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 }
Comment #1 by ibuclaw — 2015-02-01T16:07:16Z
Of course, this is a pathological case, but artificial names should never be exposed in compiler errors.
Comment #2 by k.hara.pg — 2015-02-16T15:37:56Z
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.
Comment #3 by github-bugzilla — 2015-02-18T03:03:07Z
Comment #4 by github-bugzilla — 2015-02-21T09:11:40Z
Comment #5 by razvan.nitu1305 — 2022-12-16T13:44:45Z
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?