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

Commit

Permalink
Merge pull request #1715 from denis-sh/fix-Issue-16974
Browse files Browse the repository at this point in the history
[REG2.068] Fix Issue 16974 - Equal associative arrays with associative array keys are considered unequal
  • Loading branch information
MartinNowak authored Dec 28, 2016
2 parents bf9d001 + 5cc2843 commit d57fdb1
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 d57fdb1

Please sign in to comment.