When an alias introduces a potential array, it's picked over a valid overloaded operator when doing an array operation, causing a compilation error.
(Note this issue reminds of issue #3064)
When the alias is removed, this code compiles and functions properly:
struct Vec{
int[2] list;
alias list this; // Causes failing compilation (c[]*b has b cast to int[2]).
Vec opBinary(string op)(const Vec rhs) const {
Vec newA;
mixin("newA.list[0] = list[0]"~op~"rhs.list[0];");
mixin("newA.list[1] = list[1]"~op~"rhs.list[1];");
return newA;
}
}
void main(string[]) {
Vec a;
a.list = [1,1];
Vec b;
b.list = [2,2];
Vec[2] c = [a, b];
Vec[2] d;
d[] = c[] * b;
writeln(d);
}
Comment #1 by robert.schadek — 2024-12-13T19:27:24Z