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

           Summary: Problem in AAs with fixed size arrays as keys
           Product: D
           Version: future
          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 05:37:13 PDT ---
This D2 program, compiles and run with DMD v2.046:


import std.stdio: writeln;
void main() {
    char[] txt = cast(char[])("this is just a test".dup);
    enum int N = 2;
    int[char[N]] aa;
    foreach (i; 0 .. txt.length + 1 - N) {
        char[2] key = txt[i .. i + N];
        aa[key]++;
    }
    writeln(aa);
}


The correct output:

[[t,h]:1,[i,s]:2,[u,s]:1,[t, ]:1,[ ,t]:1,[e,s]:1,[h,i]:1,[ ,i]:1,[ ,a]:1,[a,
]:1,[t,e]:1,[ ,j]:1,[s, ]:2,[j,u]:1,[s,t]:2]

-----------------

But after this small change:


import std.stdio: writeln;
void main() {
    char[] txt = cast(char[])("this is just a test".dup);
    enum int N = 2;
    int[char[N]] aa;
    foreach (i; 0 .. txt.length + 1 - N) {
        aa[txt[i .. i + N]]++;
    }
    writeln(aa);
}


It doesn't work, inside aa goes only one key-value pair.

(Similar traps are very bad in a language. In this situation I suggest to
produce a compile-time error, or better to convert the slice into the correct 2
char array to be used as key).

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

Reply via email to