Thread overview
[Issue 2608] New: int[] literal too polysemous
Jan 23, 2009
d-bugmail
Jan 23, 2009
d-bugmail
Jan 24, 2009
d-bugmail
Jan 24, 2009
d-bugmail
January 23, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2608

           Summary: int[] literal too polysemous
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: andrei@metalanguage.com


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.


-- 

January 23, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2608





------- Comment #1 from ary@esperanto.org.ar  2009-01-23 17:47 -------
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?


-- 

January 24, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2608





------- Comment #2 from andrei@metalanguage.com  2009-01-23 20:03 -------
(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.


-- 

January 24, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2608


2korden@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unspecified                 |2.021




------- Comment #3 from 2korden@gmail.com  2009-01-24 00:53 -------
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
...


-- 

October 29, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2608


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bearophile_hugs@eml.cc
         Resolution|                            |FIXED


--- Comment #4 from bearophile_hugs@eml.cc 2010-10-29 09:47:02 PDT ---
That code works with dmd 2.050.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------