No error for ambiguous struct `opCmp`
From https://dlang.org/spec/operatoroverloading.html#compare:
Both rewrites are tried... If they both match the same, but are different functions, an ambiguity error results.
The static assert below fails, the comparison can be compiled:
struct B
{
int opCmp(ref C) { return -1; }
}
struct C
{
int opCmp(ref B) { return 1; }
}
void main()
{
B b;
C c;
static assert(!__traits(compiles, b < c)); // both C.opCmp and B.opcmp match exactly
}
Note: this example is simplified from the spec, which also fails to compile.
I think this is a duplicate of #19835.
However, perhaps fixing this could break code relying on the current behaviour of using the first rewrite (i.e. left-hand expression's opCmp). In that case, another option would be to fix the docs.
Note: this example is simplified from the spec, which also fails to compile.
the spec example indeed fails to compile as documented.