Bug 4662 – Array ops on const arrays

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-08-17T07:06:00Z
Last change time
2012-07-15T07:49:23Z
Keywords
accepts-invalid, pull
Assigned to
yebblies
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-08-17T07:06:13Z
This D2 program shows two problems (dmd 2.048): void foo(const double[] arr1) { arr1[] += 1; // line 2, no error here double[] arr2; arr1[] += arr2[]; // line 4, Error here } void main() {} The first problem is at line 2, where the const nature of arr1 is ignored. The second problem is at line 4, that generates a wrong error message: test.d(4): Error: invalid array operation arr1[] += cast(const(double[]))arr2[] (did you forget a [] ?)
Comment #1 by yebblies — 2012-01-27T23:27:05Z
*** Issue 7286 has been marked as a duplicate of this issue. ***
Comment #2 by yebblies — 2012-01-27T23:38:19Z
Looks like the fix for issue 5284 only got assignment.
Comment #3 by yebblies — 2012-01-28T00:57:33Z
Comment #4 by github-bugzilla — 2012-07-14T07:19:24Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/e917e1e404f8dc6b3440788d40fcf936c51bdf57 Fix Issue 4662 - Array ops on const arrays For BinAssignExp, check that the lhs is assignable or mutable. https://github.com/D-Programming-Language/dmd/commit/738114f00b12726a14fb4a65abe825957f82875d Merge pull request #648 from yebblies/issue4662 Issue 4662 - Array ops on const arrays
Comment #5 by k.hara.pg — 2012-07-14T08:11:15Z
Additional fix for yebblies's patch: https://github.com/D-Programming-Language/dmd/pull/1046
Comment #6 by bearophile_hugs — 2012-07-15T04:15:20Z
The two problems of the example seems fixed. Now this program: void main() { const int[] a = new int[5]; int[] b = new int[5]; b[] += a[]; } Gives: test.d(4): Error: slice cast(const(int)[])b[] is not mutable I think is a rejects-valid.
Comment #7 by yebblies — 2012-07-15T06:05:17Z
(In reply to comment #6) > The two problems of the example seems fixed. Now this program: > > > void main() { > const int[] a = new int[5]; > int[] b = new int[5]; > b[] += a[]; > } > > > Gives: > test.d(4): Error: slice cast(const(int)[])b[] is not mutable > > I think is a rejects-valid. Yes, my mistake.
Comment #8 by yebblies — 2012-07-15T06:24:37Z
Ok, not really my mistake, but a problem with typeMerge or the use of typeMerge in BinAssignExp::semantic. It doesn't make any sense for a BinAssignExp or a BinAssignExp::e1 to be type-merged with the rhs, ever. Bearophile, could you please open another bug for this? It is a regression because this bug previously hid the error.
Comment #9 by bearophile_hugs — 2012-07-15T07:49:23Z
(In reply to comment #8) > Ok, not really my mistake, but a problem with typeMerge or the use of typeMerge > in BinAssignExp::semantic. It doesn't make any sense for a BinAssignExp or a > BinAssignExp::e1 to be type-merged with the rhs, ever. > > Bearophile, could you please open another bug for this? It is a regression > because this bug previously hid the error. OK, thank you for answering. I close this bug report as fixed, and I have opened a new regression, Issue 8390