Bug 6611 – better error message for array post increment/decrement

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-09-06T03:17:00Z
Last change time
2012-02-18T23:10:20Z
Keywords
diagnostic, pull
Assigned to
yebblies
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-09-06T03:17:47Z
This code contains two operations that are refused by DMD2.055beta: void main() { int[10] a; a[] += 1; // OK ++a[]; // OK --a[]; // OK a[]++; // line 6, error a[]--; // line 7, error } test2.d(6): Error: slice expression a[] is not a modifiable lvalue test2.d(6): Error: 'a[]' is not a scalar, it is a int[] test2.d(6): Error: cannot cast int to int[] test2.d(7): Error: slice expression a[] is not a modifiable lvalue test2.d(7): Error: 'a[]' is not a scalar, it is a int[] test2.d(7): Error: cannot cast int to int[] Maybe it's better to allow the last two lines too.
Comment #1 by yebblies — 2011-09-06T06:34:55Z
This line implies the following a[]++ => (auto tmp = a[].dup, ++a[], tmp) Do we really want it to be this easy to do?
Comment #2 by bearophile_hugs — 2011-09-06T10:22:34Z
(In reply to comment #1) > This line implies the following > a[]++ => (auto tmp = a[].dup, ++a[], tmp) > > Do we really want it to be this easy to do? I understand. If doing this is not good, then I suggest to turn this into a diagnostic enhancement request. So given code like this: void main() { int[10] a; a[]++; } to raise a single error message that explains why that vector op is on purpose not supported.
Comment #3 by yebblies — 2011-09-06T10:41:35Z
(In reply to comment #2) > I understand. If doing this is not good, then I suggest to turn this into a > diagnostic enhancement request. So given code like this: > It's probably not worth introducing yet another hidden allocation, or a special case as it can be easily written using pre-inc. > void main() { > int[10] a; > a[]++; > } > > > to raise a single error message that explains why that vector op is on purpose > not supported. That sounds reasonable, the error message is terrible.
Comment #4 by yebblies — 2012-02-14T07:09:34Z
Comment #5 by github-bugzilla — 2012-02-18T23:07:27Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/176b8752c6f9d92e2570bcb47b87419bf2f0ccd2 Issue 6611 - better error message for array post increment/decrement Detect attempts to use post increment/decrement on an array slice, and print a better error message. https://github.com/D-Programming-Language/dmd/commit/d082916311aca3d14e13295eaafa9b6e52cd81b3 Merge pull request #717 from yebblies/issue6611 Issue 6611 - better error message for array post increment/decrement