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