[Issue 7512] Associative arrays with dstring as key do not work correctly

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Feb 27 12:42:05 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7512



--- Comment #2 from hsteoh at quickfur.ath.cx 2012-02-27 12:42:04 PST ---
OK, I've narrowed down this bug to using an AA literal for when the key is a
non-string array. For some strange reason, the AA literal *appears* to
correctly initialize the AA, as far as foreach can tell:

// CODE:
const int[] key1 = [1,2,3];
const int[] key2 = [1,2,4];
int[int[]] a5 = [
    key1 : 3,
    key2 : 4
];
foreach (key, val; a5) {
    writefln("%s -> %s", key, val);
}

// OUTPUT:
[1, 2, 3] -> 3
[1, 2, 4] -> 4

Seems to be correct, however:

// CODE:
foreach (key, val; a5) {
    assert(a5[key]==val);
}

// OUTPUT:
core.exception.AssertError at aatest(15): Assertion failure

This is the failing case. However, if we *don't* use an AA literal:

// CODE:
const int[] key1 = [1,2,3];
const int[] key2 = [1,2,4];
int[int[]] a5;
a5[key1] = 3;
a5[key2] = 4;
foreach (key, val; a5) {
    assert(a5[key]==val);
}


Then there is no assertion failure.

Conclusion: something screwy is going on when an AA literal is used. The AA
appears to be initialized correctly, and foreach appears to return the correct
key/value pairs, *but* attempting to do lookups with the keys fails for some
unknown reason.

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


More information about the Digitalmars-d-bugs mailing list