D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14102 - Bad 'is not an lvalue' diagnostic in chained -unary and --preincr expressions.
Summary: Bad 'is not an lvalue' diagnostic in chained -unary and --preincr expressions.
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2015-02-01 16:06 UTC by Iain Buclaw
Modified: 2022-12-16 13:44 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Iain Buclaw 2015-02-01 16:06:21 UTC
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 Iain Buclaw 2015-02-01 16:07:16 UTC
Of course, this is a pathological case, but artificial names should never be exposed in compiler errors.
Comment 2 Kenji Hara 2015-02-16 15:37:56 UTC
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 github-bugzilla 2015-02-18 03:03:07 UTC
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
Comment 5 RazvanN 2022-12-16 13:44:45 UTC
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?