digitalmars.D - struct opEquals bug
- Sean Eskapp (29/29) Feb 17 2011 Has this been reported?
- Jason House (2/3) Feb 17 2011 Do what any of us would do... Search bugzilla and that as a bug if you d...
- Don (2/38) Feb 17 2011 Yes, it is bug 3659.
Has this been reported? struct A { int x; A foo() { return A(x); } const bool opEquals(ref const A other) { return (x == other.x); } } void main() { auto a = A(5); assert(a == a.foo); // Error assert(a.foo == a); // OK } The first assert fails to compile because a.foo isn't an lvalue, but the second assert compiles fine. However, the language documentation states that "...the 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). If one is a better match then the other, or one compiles and the other does not, the one is selected. Otherwise, an error results." In this case, a.opEquals(b) doesn't compile, but b.opEquals(a) does, so it should be selected.
Feb 17 2011
Sean Eskapp Wrote:Has this been reported?Do what any of us would do... Search bugzilla and that as a bug if you don't find it.
Feb 17 2011
Sean Eskapp wrote:Has this been reported? struct A { int x; A foo() { return A(x); } const bool opEquals(ref const A other) { return (x == other.x); } } void main() { auto a = A(5); assert(a == a.foo); // Error assert(a.foo == a); // OK } The first assert fails to compile because a.foo isn't an lvalue, but the second assert compiles fine. However, the language documentation states that "...the 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). If one is a better match then the other, or one compiles and the other does not, the one is selected. Otherwise, an error results." In this case, a.opEquals(b) doesn't compile, but b.opEquals(a) does, so it should be selected.Yes, it is bug 3659.
Feb 17 2011