Bug 3927 – array.length++; is an error, but ++array.length compiles

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-03-10T10:12:00Z
Last change time
2012-04-11T01:02:09Z
Keywords
diagnostic, rejects-valid
Assigned to
yebblies
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-03-10T10:12:01Z
With the following D2 program: void main() { int[] array; array.length++; array.length--; } The compiler shows the following errors, is this correct? test1.d(3): Error: a.length is not an lvalue test1.d(4): Error: a.length is not an lvalue
Comment #1 by clugdbug — 2012-02-01T04:27:31Z
++array.length; compiles. The bizarre error is because of the lowering that the compiler uses internally.
Comment #2 by yebblies — 2012-02-01T08:32:09Z
Comment #3 by github-bugzilla — 2012-02-22T01:31:11Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/38c9dcde7b25415adf6a1ef2f3eddd83af3a59a8 fix Issue 3927 - array.length++; is an error, but ++array.length compiles
Comment #4 by bugzilla — 2012-02-22T01:31:32Z
Fixed for D2 only.
Comment #5 by salihdb — 2012-02-22T06:45:38Z
(In reply to comment #4) > Fixed for D2 only. void main() { int[] array = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; writeln(array, "~", ++array.length, "->", --array.length); assert (array.length == 10); // no problem ++array.length; --array.length; writeln(array, "~", array.length); } DMD version: 2.057 ================== salih@DB-N150-N210-N220:~/d.ders$ ./dene [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]~11->10 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]~10 No problem...
Comment #6 by yebblies — 2012-02-22T07:01:42Z
(In reply to comment #5) > (In reply to comment #4) > > Fixed for D2 only. > > void main() { > int[] array = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; > writeln(array, "~", ++array.length, > "->", --array.length); > assert (array.length == 10); // no problem > ++array.length; > --array.length; > writeln(array, "~", array.length); > } > > DMD version: 2.057 > ================== > salih@DB-N150-N210-N220:~/d.ders$ ./dene > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]~11->10 > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]~10 > > No problem... Huh? What's your point?
Comment #7 by salihdb — 2012-02-22T09:56:23Z
I'm new learning to java language! Just tried it and I see no problem ...:) I thank you for your interest in my code snippets... Best Regards...
Comment #8 by clugdbug — 2012-04-11T01:02:09Z
Fixed, this was a D2-only bug (on D1, ++arr.length doesn't work either).