Bug 2173 – foreach iteration not possible for associative array indexed with static array

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2008-06-25T11:38:00Z
Last change time
2014-02-24T16:00:18Z
Keywords
patch, rejects-valid
Assigned to
bugzilla
Creator
georg

Comments

Comment #0 by georg — 2008-06-25T11:38:19Z
Trying to foreach through an AA[SA] generates a compiler error: import std.stdio; import std.md5; int main(char[][] args) { int[ubyte[16]] md5count; foreach (md5, count; md5count) writefln("%s: %d", std.md5.digestToString(md5), count); return 0; } Both gdc and dmd bail out on the foreach statement with: "test.d(5): Error: cannot have out or ref parameter of type ubyte[16u]" Possible workarounds: * use a wrapper struct for the static array (looks ugly) * use foreach (md5; md5count.keys) ... count = md5count[md5] (decreases performance almost by 50%)
Comment #1 by davidl — 2008-06-26T01:39:30Z
i bet the code actually meant as following: mtype.c (2790): if (arg->storageClass & (STCout | STCref | STClazy)) { --- if (t->ty == Tsarray) +++ if (t->ty != Tsarray) error(loc, "cannot have out or ref parameter of type %s", t->toChars()); } I hand-crafted a dmd which bypass this check, it can generate correct binary.
Comment #2 by davidl — 2008-07-02T09:12:09Z
umm, the patch is incorrect.. bypassing the whole test should work. /* if (arg->storageClass & (STCout | STCref | STClazy)) { if (t->ty == Tsarray) if (t->ty != Tsarray) error(loc, "cannot have out or ref parameter of type %s", t->toChars()); } */
Comment #3 by bearophile_hugs — 2010-02-18T11:09:11Z
I think this bug is now fixed, because fixed-sized arrays are managed by value.