wilzbach / tools-test

1 stars 0 forks source link

Cannot foreach over AA with char as key type #63

Closed wilzbach closed 9 years ago

wilzbach commented 13 years ago

Note: the issue was created automatically migrated from https://issues.dlang.org

Original bug ID: BZ#6425 From: Aleksandar Ruzicic <ruzicic.aleksandar@gmail.com> Reported version: D2 CC: andrej.mitrovich@gmail.com, bearophile_hugs@eml.cc, hsteoh@quickfur.ath.cx, lovelydear@mailmetrash.com

wilzbach commented 13 years ago

Comment author: Aleksandar Ruzicic <ruzicic.aleksandar@gmail.com>

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); }


wilzbach commented 13 years ago

Comment author: 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

wilzbach commented 12 years ago

Comment author: SomeDude <lovelydear@mailmetrash.com>

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

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