Bug 1727 – Associate Array Literals regression

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2007-12-11T23:27:00Z
Last change time
2015-06-09T01:14:23Z
Keywords
rejects-valid
Assigned to
bugzilla
Creator
davidl

Comments

Comment #0 by davidl — 2007-12-11T23:27:28Z
Following does not compile: int[char[]] ca= [cast(char[])"asdf":1,cast(char[])"asdf1":2];
Comment #1 by davidl — 2007-12-11T23:28:30Z
It's blocking my code from porting to D2.0. So I mark this at a little higher priority .
Comment #2 by aldacron — 2007-12-12T09:25:20Z
[email protected] wrote: > http://d.puremagic.com/issues/show_bug.cgi?id=1727 > > Summary: Associate Array Literals regression > Following does not compile: > int[char[]] ca= [cast(char[])"asdf":1,cast(char[])"asdf1":2]; When did this ever compile? I think this is an unimplemented feature, not a regression.
Comment #3 by davidl — 2007-12-13T02:20:31Z
Oh, you remind me that the severity is regression. It compiles by D1.X compilers. And spec gives a simplest example with same length string literals If I remember correctly: int[char[]] aa=["aa":1,"bb":2,"cc":3];
Comment #4 by matti.niemenmaa+dbugzilla — 2007-12-13T04:40:13Z
It has never compiled, neither in 1.0 nor in 2.0. http://www.digitalmars.com/d/expression.html#AssocArrayLiteral gives the example "[21u:"he",38:"ho",2:"hi"];" but doesn't assign it to anything. It also says "[a]n AssocArrayLiteral cannot be used to statically initialize anything." This means that code of the form "<associative array type> foo = <associative array literal>" doesn't work, nor has it ever. Unless code like the following fails, this is an invalid bug: int[char[]] a; static this() { a = ["aa":1,"bb":2,"cc":3]; }
Comment #5 by gide — 2007-12-13T13:15:50Z
The following code compiles on both GDC and DMD, but DMD compiled code throws an array bounds exception when executed. I think DMD might have a bug. test.d ------ import std.stdio; void main() { int[char[]] aa = ["aa":1, "bb":2, "cc":3]; // Fails //int[char[]] aa; aa = ["aa":1, "bb":2, "cc":3]; // Fails //int[char[]] aa; aa["aa"] = 1; aa["bb"] = 2; aa["cc"] = 3; // OK assert(aa.length == 3); assert(aa["aa"]==1); // Fails on DMD 2.008. Error: ArrayBoundsError test(8) assert(aa["bb"]==2); assert(aa["cc"]==3); writefln(aa["aa"],aa["bb"],aa["cc"]); // On GDC outputs: 123 }
Comment #6 by gide — 2008-10-25T05:28:14Z
Fixed in DMD v2.020