[Issue 21205] New: Struct comparison does not follow spec
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Aug 28 13:22:49 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=21205
Issue ID: 21205
Summary: Struct comparison does not follow spec
Product: D
Version: D2
Hardware: All
OS: Windows
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: simen.kjaras at gmail.com
>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
--
More information about the Digitalmars-d-bugs
mailing list