[Issue 16199] Looking up string-keyed AA with char[n] compiles but crashes at runtime

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Jun 23 09:32:24 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16199

--- Comment #2 from hsteoh at quickfur.ath.cx ---
Note that there's another latent bug here: looking up char[] in int[string]
compiles (and works), but the incoming char[] should not implicitly convert to
string, because the chars are mutable. However, the AA implementation receives
keyti as the TypeInfo for string, i.e., immutable(char)[].

The current implementation, of course, doesn't rely on the immutability of the
key, but conceivably it could, in which case it will break immutability when
char[] is passed in.

I don't know how to solve this within the current AA implementation framework
-- it's very messy that the incoming key type can be different but (almost)
compatible with the AA's key type. Since a few releases ago the compiler has
forced an implicit const on AA key types, but still, that doesn't fully solve
the problem, because you could construct a mutable key, e.g., char[], which
implicitly converts to the key type const(char)[], but after you insert the key
into the AA you can mutate the key via the char[]. This will break the AA,
because the stored hash now doesn't match the key, so the inserted entry cannot
be found by looking up the key.

--


More information about the Digitalmars-d-bugs mailing list