Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Fix Issue 16974 - Equal associative arrays with associative array key…
Browse files Browse the repository at this point in the history
…s are considered unequal

Use correct overload of `hashOf` in `_aaGetHash`.

This incorrect usage is possible because of Issue 16973 - `hashOf` has error-prone signature as `(T, seed)` may be confused with `(ptr, length)` [1].

[1] https://issues.dlang.org/show_bug.cgi?id=16973
  • Loading branch information
denis-sh committed Dec 17, 2016
1 parent 422c8f7 commit 5cc2843
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/rt/aaA.d
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ extern (C) hash_t _aaGetHash(in AA* aa, in TypeInfo tiRaw) nothrow
continue;
size_t[2] h2 = [b.hash, valHash(b.entry + off)];
// use XOR here, so that hash is independent of element order
h ^= hashOf(h2.ptr, h2.length * h2[0].sizeof);
h ^= hashOf(h2);
}
return h;
}
Expand Down Expand Up @@ -1001,3 +1001,15 @@ pure nothrow unittest
assert(aa.length == 1);
assert(aa[5] == 6);
}

// test AA as key (Issue 16974)
unittest
{
int[int] a = [1 : 2], a2 = [1 : 2];

assert([a : 3] == [a : 3]);
assert([a : 3] == [a2 : 3]);

assert(typeid(a).getHash(&a) == typeid(a).getHash(&a));
assert(typeid(a).getHash(&a) == typeid(a).getHash(&a2));
}

0 comments on commit 5cc2843

Please sign in to comment.