struct opEquals bug

Sean Eskapp eatingstaples at gmail.com
Thu Feb 17 16:38:50 PST 2011


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.


More information about the Digitalmars-d mailing list