[Issue 3844] New: Require opEquals/opCmp in a class the defines toHash

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Feb 23 17:38:35 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=3844

           Summary: Require opEquals/opCmp in a class the defines toHash
           Product: D
           Version: 2.040
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2010-02-23 17:38:34 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list