www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6425] New: Cannot foreach over AA with char as key type

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

           Summary: Cannot foreach over AA with char as key type
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Optlink
        AssignedTo: nobody puremagic.com
        ReportedBy: ruzicic.aleksandar gmail.com



2011-08-01 18:37:36 CEST ---
This code:

--------------------------------------

string[char] aa = [
  'f': "foo",
  'b': "bar"
];

foreach (ch, str; aa) {
  writefln("[%s]: [%s]", ch, str);
}

--------------------------------------

Compiles fine but optlink complains:

OPTLINK (R) for Win32  Release 8.00.12
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
test.obj(test)
 Error 42: Symbol Undefined
_D6object28__T16AssociativeArrayTaTAyaZ16AssociativeArray7opApplyMFMDFKaKAyaZiZi
--- errorlevel 1


while this compiles and links without problem:

--------------------------------------

string[string] aa = [
    "f": "foo",
    "b": "bar"
];

foreach (ch, str; aa) {
    writefln("[%s]: [%s]", ch, str);
}

--------------------------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 01 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6425


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc



Playing a bit with your test-case I have found this:


void main() {
    foreach (c, str; ['f': "foo"])
        c++;
}


Internal error: e2ir.c 4883

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 01 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6425


SomeDude <lovelydear mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear mailmetrash.com



PDT ---
On 2.059, this gives:
PS E:\DigitalMars\dmd2\samples> rdmd  bug.d
bug.d(3): Error: non-constant expression ['f':"foo",'b':"bar"]

unless one defines:
enum string[char] aa = ['f': "foo",'b': "bar"];

(See issue 5279)
But with the above declaration, both description and comment 1 test cases run
fine.

Test case of description
PS E:\DigitalMars\dmd2\samples> rdmd  bug.d
[b]: [bar]
[f]: [foo]

So I suggest we close this issue while keeping issue 5279 open.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 27 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6425


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |WORKSFORME


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