Thread overview
[Issue 1640] New: Can't slice array literal directly
Nov 04, 2007
d-bugmail
Nov 04, 2007
d-bugmail
Nov 05, 2007
d-bugmail
Sep 05, 2008
d-bugmail
November 04, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1640

           Summary: Can't slice array literal directly
           Product: D
           Version: 1.022
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: matti.niemenmaa+dbugzilla@iki.fi


void main() {
        int[] foo = [1,2,3][];
}

asdf.d(2): semicolon expected, not '['

void main() {
        int[] foo = [1,2,3][0..1];
}

asdf.d(2): semicolon expected, not '['
asdf.d(2): found '..' when expecting ','


-- 

November 04, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1640





------- Comment #1 from aziz.kerim@gmail.com  2007-11-04 12:27 -------
The array literal is parsed as an array initializer (which must be followed by a semicolon.) You can work around this quite easily:

int[] foo = ([1,2,3])[0..1];


-- 

November 05, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1640





------- Comment #2 from matti.niemenmaa+dbugzilla@iki.fi  2007-11-05 01:05 -------
I knew about this workaround, just forgot to mention it. The other, of course, is to do:

int[] foo = [1,2,3];
foo = foo[0..1];

It's still a bug, though.


-- 

September 05, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1640


matti.niemenmaa+dbugzilla@iki.fi changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #3 from matti.niemenmaa+dbugzilla@iki.fi  2008-09-05 10:07 -------
Fixed in DMD 1.035, though not marked as such in the changelog.


--