Bug 1640 – Can't slice array literal directly

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2007-11-04T11:51:00Z
Last change time
2014-02-24T15:33:39Z
Keywords
rejects-valid
Assigned to
bugzilla
Creator
matti.niemenmaa+dbugzilla

Comments

Comment #0 by matti.niemenmaa+dbugzilla — 2007-11-04T11:51:57Z
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 ','
Comment #1 by aziz.koeksal — 2007-11-04T12:27:52Z
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];
Comment #2 by matti.niemenmaa+dbugzilla — 2007-11-05T01:05:42Z
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.
Comment #3 by matti.niemenmaa+dbugzilla — 2008-09-05T10:07:15Z
Fixed in DMD 1.035, though not marked as such in the changelog.