Bug 3844 – Require opEquals/opCmp in a class the defines toHash
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-02-23T17:38:34Z
Last change time
2018-07-02T18:51:58Z
Assigned to
No Owner
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2010-02-23T17:38:34Z
This code compiles and runs:
class Foo {
int a, b;
override hash_t toHash() { return a + b; }
this(int aa, int bb) { this.a = aa; this.b = bb; }
}
void main() {
int[Foo] aa1;
aa1[new Foo(1, 2)] = 10;
}
I think in a class it's not that useful to define toHash and not define opEquals/opCmp too. So when a toHash is defined, the compiler can raise a warning to require the definition of an opEquals/opCmp too.
Comment #1 by bearophile_hugs — 2010-06-06T13:09:51Z