digitalmars.D.bugs - [Issue 13045] New: TypeInfo.getHash should return consistent result
- via Digitalmars-d-bugs (58/58) Jul 04 2014 https://issues.dlang.org/show_bug.cgi?id=13045
https://issues.dlang.org/show_bug.cgi?id=13045 Issue ID: 13045 Summary: TypeInfo.getHash should return consistent result with object equality by default Product: D Version: D2 Hardware: All OS: All Status: NEW Keywords: wrong-code Severity: blocker Priority: P1 Component: DMD Assignee: nobody puremagic.com Reporter: k.hara.pg gmail.com 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 } --
Jul 04 2014