One old problem with associative arrays

bearophile bearophileHUGS at lycos.com
Tue Nov 6 20:08:43 PST 2012


import std.stdio;
void main() {
     int[] a;
     int[int] aa;
     a ~= a.length;
     aa[10] = aa.length;
     writeln(a, " ", aa);
     a ~= a.length;
     aa[20] = aa.length;
     writeln(a, " ", aa);
}


It prints:

[0] [10:1]
[0, 1] [20:2, 10:1]

So the associative array is updated before taking its length. I 
suggest to try to fix this AA behavour before too much D2 code 
relies on this. I'd like to avoid this to become a permanent wart 
of D2.

My bug report is from February 2010, it's in the most important 
20 bug reports of mine. In my opinion it's wrong to add new 
features to D before similar bugs are fixed:

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

Thank you,
bye,
bearophile


More information about the Digitalmars-d mailing list