Bug 2608 – int[] literal too polysemous

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2009-01-23T16:22:00Z
Last change time
2015-06-09T01:20:45Z
Assigned to
nobody
Creator
andrei

Comments

Comment #0 by andrei — 2009-01-23T16:22:45Z
The following code fails: void next(T)(ref T[] a) { assert(a.length); a = a[1 .. $]; } void main() { auto a = [ 1, 2, 3 ]; a.next; assert(a == [ 2, 3 ]); } If one replaces "auto" with "int[]", the code compiles and runs as expected. It looks like auto with literals tries too hard to keep it around as an rvalue. This seems to be related to issue 2606.
Comment #1 by ary — 2009-01-23T17:47:05Z
The problem is that an array literal has a static array type by default. Wouldn't it be more user-friendly for it to be a dynamic array type?
Comment #2 by andrei — 2009-01-23T20:03:18Z
(In reply to comment #1) > The problem is that an array literal has a static array type by default. > Wouldn't it be more user-friendly for it to be a dynamic array type? Oh, you are right. Walter did change the default type of literals to dynamic-length, but apparently only for strings.
Comment #3 by 2korden — 2009-01-24T00:53:33Z
Could you please post generated error message, too, so that other don't have to guess? :) ... a.next; // Error: cast(int[])a is not an lvalue ...
Comment #4 by bearophile_hugs — 2010-10-29T09:47:02Z
That code works with dmd 2.050.