www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19365] New: operator overloading set of mixin template is not


          Issue ID: 19365
           Summary: operator overloading set of mixin template is not
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dkorpel live.nl

I'm trying to mixin generic operator overloads for + and -, and then add
specialized operators for * and /. Minimized code:

mixin template Operators() {
    int opBinary(string op: "+")(S rhs) {return 1;}

struct S {
    mixin Operators;
    int opBinary(string op: "*")(S rhs) {return 2;}

void main() {
    import std.stdio;
    S s;
    writeln(s * s); // 2
    writeln(s + s); // incompatible types for (s) + (s)
    writeln(s.opBinary!"+"(s)); //`opBinary!"+"` does not match template
declaration opBinary(string op : "*")(S rhs)

While opBinary!"+" and opBinary!"*" work in isolation, the prescence of
opBinary!"*" completely shadows the opBinary!"+" template in the mixin. I
expect both the normal and mixed in opBinary templates to be operator
overloading candidates.

Nov 05 2018