www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11025] New: std.typecons.Tuple needs to define toHash

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

           Summary: std.typecons.Tuple needs to define toHash
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: hsteoh quickfur.ath.cx


--- Comment #0 from hsteoh quickfur.ath.cx 2013-09-13 13:14:57 PDT ---
Code:
------
import std.typecons;
void main() {
        bool[Tuple!(string,string)] aa;
        aa[tuple("a", "b")] = true;
        assert(tuple("a", "b") in aa); // OK due to folding of identical string
literals
        assert(tuple("a".idup, "b".idup) in aa); // NG
}
------

Proof that toHash is the problem:
------
import std.typecons, std.stdio;
void main() {
        auto t = tuple("a", "b");
        auto u = tuple("a".idup, "b".idup);
        writeln(typeid(t).getHash(&t)); // prints 18075234133232566449
        writeln(typeid(u).getHash(&u)); // prints 5823865589096027868
}
------

It appears that the hash is computed only on the binary representation of the
tuple, not on the contents of each field. This causes the AA breakage above.

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