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

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jul 23 07:56:18 PDT 2014


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

Kenji Hara <k.hara.pg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #7 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to bearophile_hugs from comment #3)
> opCmp includes an equality, this means the programmer has defined an
> equality too. So can't we assume that the equality is "t1.opCmp(t2) == 0"
> when the user defines just opCmp?

But currently `a == b` is never rewritten to `a.opCmp(b) == 0`. It's in a
domain of enhancement request that requires more discussion.

(In reply to hsteoh from comment #4)
> By your logic, the compiler should reject "a == b" when the programmer
> hasn't defined opEquals, because the compiler cannot know whether
> a.opCmp(b)==0 is what the programmer is expecting. I don't understand how
> this could make any sense.

It's not a logic issue. If opCmp is defined and `a == b` will be automatically
rewritten to `a.opCmp(b) == 0`, the code behavior will be _silently_ changed.

So compiler reports a diagnostic error. It's far better than silent changing.

--


More information about the Digitalmars-d-bugs mailing list