[Issue 13179] AA key type TagIndex now requires equality rather than comparison

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Jul 21 23:25:35 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=13179

--- Comment #5 from Jacob Carlborg <doob at me.com> ---
(In reply to Kenji Hara from comment #2)

> It's intended behavior, because compiler cannot know whether the generated
> opEquals is what programmer is expecting.

As others have already said, if opCmp is defined then the compiler can generate
opEquals that calls opCmp.

> In D, all struct define default member-wise equality for == operator.
> 
> TagIndex t1, t2;
> // t1 == t2 will be rewritten as:
> //    t1.tupleof == t2.tupleof
> // and then it will mean:
> //    t1.tag == t2.tag && t1.index == t2.index
> 
> If TagIndex is used for AA keys, compiler cannot determine which is the
> intended 'equality', t1 == t2 or t1.opCmp(t2) == 0.
> 
> So compiler requests you to resolve the ambiguity by defining opEquals or
> removing opCmp.

opCmp was added because of a regression in 2.065.0 and now it's changed again.

--


More information about the Digitalmars-d-bugs mailing list