Summary: A bug-prone situation with AAs
           Product: D
           Version: 2.040
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime

--- Comment #0 from 2010-02-18 12:26:51 PST ---
import std.stdio;
void main() {
    string[] words = ["how", "are", "you", "are"];

    int[string] aa1;
    foreach (w; words)
        aa1[w] = ((w in aa1) ? (aa1[w] + 1) : 2);
    writeln(aa1); // Prints: [how:1,you:1,are:2]

    int[string] aa2;
    foreach (w; words)
        if (w in aa2)
            aa2[w] = 2;
    writeln(aa2); // Prints: [how:2,you:2,are:3]

This can be a source of bugs in programs. I don't know if there are ways to
help the programmer avoid this bug.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to