www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1727] New: Associate Array Literals regression

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1727

           Summary: Associate Array Literals regression
           Product: D
           Version: 2.008
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: davidl 126.com


Following does not compile:
int[char[]] ca= [cast(char[])"asdf":1,cast(char[])"asdf1":2];


-- 
Dec 11 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1727


davidl 126.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |major
           Priority|P2                          |P1




------- Comment #1 from davidl 126.com  2007-12-11 23:28 -------
It's blocking my code from porting to D2.0. So I mark this at a little higher
priority .


-- 
Dec 11 2007
prev sibling next sibling parent reply Don Clugston <dac nospam.com.au> writes:
d-bugmail puremagic.com 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.
Dec 12 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Don Clugston" <dac nospam.com.au> wrote in message 
news:fjoue2$o1o$1 digitalmars.com...
 d-bugmail puremagic.com 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.

Uh, are you talking about AA literals? They've been in D since 1.014 (April 26).. this code works with D1.
Dec 12 2007
parent reply Matti Niemenmaa <see_signature for.real.address> writes:
Jarrett Billingsley wrote:
 "Don Clugston" <dac nospam.com.au> wrote in message 
 news:fjoue2$o1o$1 digitalmars.com...
 d-bugmail puremagic.com 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];

a regression.

Uh, are you talking about AA literals? They've been in D since 1.014 (April 26).. this code works with D1.

It won't compile at global scope, and never has. http://www.digitalmars.com/d/1.0/expression.html#AssocArrayLiteral "An AssocArrayLiteral cannot be used to statically initialize anything." -- E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi
Dec 12 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Matti Niemenmaa" <see_signature for.real.address> wrote in message 
news:fjpbvo$1s6a$1 digitalmars.com...
 It won't compile at global scope, and never has.

 http://www.digitalmars.com/d/1.0/expression.html#AssocArrayLiteral

 "An AssocArrayLiteral cannot be used to statically initialize anything."

Then it's not a bug in any way, is it? It's stupid, but according to spec. And it's not a regression because nothing changed. It works fine in 2.008 too.
Dec 12 2007
parent Matti Niemenmaa <see_signature for.real.address> writes:
Jarrett Billingsley wrote:
 "Matti Niemenmaa" <see_signature for.real.address> wrote in message 
 news:fjpbvo$1s6a$1 digitalmars.com...
 It won't compile at global scope, and never has.

 http://www.digitalmars.com/d/1.0/expression.html#AssocArrayLiteral

 "An AssocArrayLiteral cannot be used to statically initialize anything."

Then it's not a bug in any way, is it? It's stupid, but according to spec. And it's not a regression because nothing changed. It works fine in 2.008 too.

I don't have a 2.0 installation handy so I don't know, but yes: if it works fine when doing the initialization in a static constructor, for instance, then it's not a bug. -- E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi
Dec 12 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1727


davidl 126.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|major                       |regression




------- Comment #3 from davidl 126.com  2007-12-13 02:20 -------
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]; 


-- 
Dec 13 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1727


matti.niemenmaa+dbugzilla iki.fi changed:

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




------- Comment #4 from matti.niemenmaa+dbugzilla iki.fi  2007-12-13 04:40
-------
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];
}


-- 
Dec 13 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1727


gide nwawudu.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |




------- Comment #5 from gide nwawudu.com  2007-12-13 13:15 -------
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
}


-- 
Dec 13 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1727


gide nwawudu.com changed:

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




------- Comment #6 from gide nwawudu.com  2008-10-25 05:28 -------
Fixed in DMD v2.020


-- 
Oct 25 2008