struct opEquals bug
Don
nospam at nospam.com
Thu Feb 17 22:09:20 PST 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.
More information about the Digitalmars-d
mailing list