On Friday, 22 July 2022 at 12:33:37 UTC, Anthony Quizon wrote:
Is this a bug or am I doing something wrong?

I think this is a bug. The compiler must not take well to this pattern, maybe the assoc array template argument, but idk. It looks like the first type used gets cached and reused even if it is supposed to change.

I vaguely recall seeing this before.... but yeah smells buggy anyway.


An alternative you might consider is dropping some of the type and using typeof(this):

```
module foo;

mixin template opBi(
    alias f0
) {
    static foreach (k, f; f0) { typeof(this) opBinary(string op:
    k)(typeof(this) r) { return f(this, r); } }
}

struct A {
    mixin opBi!(
        [ "+": (A a, A b) => a],
    );
}

struct B {
    mixin opBi!(
        [ "+": (B a, B b) => a],
    );
}
```

That sidesteps the bug though it just trusts you pass the right type to `f0`.

Reply via email to