[Issue 5835] `TypeInfo_Array.getHash` creates raw data hash instead using array element hash function
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Mar 6 01:58:18 PST 2014
https://d.puremagic.com/issues/show_bug.cgi?id=5835
Denis Shelomovskij <verylonglogin.reg at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
CC| |verylonglogin.reg at gmail.com
Summary|Class array's |`TypeInfo_Array.getHash`
|TypeInfo.getHash doesn't |creates raw data hash
|work correctly |instead using array element
| |hash function
--- Comment #5 from Denis Shelomovskij <verylonglogin.reg at gmail.com> 2014-03-06 13:57:36 MSK ---
Simplified original testcase:
---
class S
{
int i;
this(in int i) { this.i = i; }
override hash_t toHash() { return 0; }
}
void main()
{
S[] a1 = [new S(11)], a2 = [new S(12)];
assert(typeid(S[]).getHash(&a1) == typeid(S[]).getHash(&a2)); // fails
}
---
With structs:
---
struct S
{
int i;
hash_t toHash() const @safe nothrow { return 0; }
}
void main()
{
S[] a1 = [S(11)], a2 = [S(12)];
assert(typeid(S[]).getHash(&a1) != typeid(S[]).getHash(&a2)); // fails
}
---
Associative arrays are affected too because of this:
---
struct S
{
int i;
hash_t toHash() const @safe nothrow { return 0; }
bool opEquals(ref const S el) const { return true; }
int opCmp(ref const S el) const { return 0; }
}
void main()
{
int[S[]] aa = [[S(11)] : 13];
assert([S(12)] in aa); // fails
}
---
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list