http://d.puremagic.com/issues/show_bug.cgi?id=4279
Summary: AAs change key type Product: D Version: unspecified Platform: x86 OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: druntime AssignedTo: s...@invisibleduck.org ReportedBy: bearophile_h...@eml.cc --- Comment #0 from bearophile_h...@eml.cc 2010-06-06 04:54:52 PDT --- With DMD v2.046 this program prints const(char)[] instead of char[] import std.stdio: writeln; void main() { int[char[]] data = [cast(char[])"foo" : 1]; foreach (key, val; data) writeln(typeid(typeof(key))); } Modifying AA keys after they are inserted in the AA is indeed bad because their hash value and position inside the AA doesn't get recomputed. But the current design/behaviour is surprising and bad, because I have asked for a key type and the runtime/compiler gives me a different key type (forcing me to use casts). There are two possible behaviours that I see acceptable here: 1) to disallow AAs with mutable keys, their literals and definition too (as Python does), so in this case this variable definition becomes a compile-time error: int[int[]] data; 2) or to allow mutable keys (and hope the programmer will not mutate them) (as I think D1 does), and keep their type unchanged (mutable). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------