Bug 21205 – Struct comparison does not follow spec

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2020-08-28T13:22:49Z
Last change time
2024-12-13T19:11:17Z
Assigned to
No Owner
Creator
Simen Kjaeraas
Moved to GitHub: dmd#19778 →

Comments

Comment #0 by simen.kjaras — 2020-08-28T13:22:49Z
From https://dlang.org/spec/operatoroverloading.html#equals: 2. [T]he expressions a.opEquals(b) and b.opEquals(a) are tried. If both resolve to the same opEquals function, then the expression is rewritten to be a.opEquals(b). 3. If one is a better match than the other, or one compiles and the other does not, the first is selected. 4. Otherwise, an error results. Clearly, this is not the case: struct S1 { bool opEquals(S2 a) { return true; } } struct S2 { bool opEquals(S1 a) { return false; } } static assert((S1.init == S2.init) == (S2.init == S1.init)); // Fails
Comment #1 by razvan.nitu1305 — 2020-09-15T04:11:42Z
Hmmm...here we have equal match for both functions therefore, according to the spec, we should have an error, however, the compiler chooses the first function that. I'm not sure if this is a feature or a bug (should we change the spec or modify the behavior of the compiler?).
Comment #2 by robert.schadek — 2024-12-13T19:11:17Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19778 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB