dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Array comparison with recursive inferred opEquals gives confusing error message

Open jamesragray opened this issue 7 months ago • 1 comments

The following code:

struct A {
    A[] as;
    auto opEquals(A x) {
        return as == x.as;
    }
}

void main() {
    
}

produces the compiler error:

 Error: incompatible types for array comparison: `A[]` and `A[]`

Replacing auto with bool causes it to compile. I guess one would expect an error of the form:

can't infer return type  in function opEquals...

jamesragray avatar May 25 '25 21:05 jamesragray

Note, if you don't use array comparisons but simply recurse, you get this:

struct A {
    A[] as;
    auto opEquals(A x) {
        return x == this;
    }
}
Error: forward reference to inferred return type of function call `x.opEquals(this)`

I would expect a similar error for the array form.

schveiguy avatar May 25 '25 21:05 schveiguy