Bug 13045 – TypeInfo.getHash should return consistent result with object equality by default
Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-07-04T16:29:00Z
Last change time
2014-07-06T01:13:53Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2014-07-04T16:29:51Z
This test case should succeed to run, but doesn't.
struct S
{
int[] a;
}
void main()
{
auto s1 = S([1,2]);
auto s2 = S([1,2]);
assert(s1 !is s2);
assert(s1 == s2);
assert(typeid(S).getHash(&s1) == typeid(S).getHash(&s2));
// -> assert should pass, but doesn't
}
And, TypeInfo.getHash should also support composed hash calculation.
struct S
{
size_t toHash() const nothrow @safe
{
assert(0); // all getHash call should reach here
}
}
struct T
{
S s;
}
void main()
{
import std.exception : assertThrown;
S s;
assertThrown!Error(typeid(S).getHash(&s)); // OK
S[1] ssa;
assertThrown!Error(typeid(S[1]).getHash(&ssa)); // OK
S[] sda = [S(), S()];
assertThrown!Error(typeid(S[]).getHash(&sda)); // OK
T t;
assertThrown!Error(typeid(T).getHash(&t)); // should pass
T[1] tsa;
assertThrown!Error(typeid(T[1]).getHash(&tsa)); // should pass
T[] tda = [T(), T()];
assertThrown!Error(typeid(T[]).getHash(&tda)); // should pass
}