[Issue 12159] New: cannot overload same operator in different mixin templates

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Feb 14 05:12:38 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=12159

           Summary: cannot overload same operator in different mixin
                    templates
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: maximzms at gmail.com


--- Comment #0 from Maksim Zholudev <maximzms at gmail.com> 2014-02-14 05:12:34 PST ---
----------------------------------------
// test1.d

mixin template Plus()
{
    void foo(string op, T)(T src)
        if(op == "+") {}
    void opOpAssign(string op, T)(T src)
        if(op == "+") {}
}

mixin template Minus()
{
    void foo(string op, T)(T src)
        if(op == "-") {}
    void opOpAssign(string op, T)(T src)
        if(op == "-") {}
}

struct Boo
{
    mixin Plus;
    mixin Minus;
}

void main()
{
    Boo a, b;
    a.foo!"+"(b); // OK
    a.foo!"-"(b); // OK
    a += b;       // (30): Error
    a -= b;       // (31): Error
}
----------------------------------------
$ dmd test1.d
test1.d(30): Error: 'a += b' is not a scalar, it is a Boo
test1.d(30): Error: 'a' is not of arithmetic type, it is a Boo
test1.d(30): Error: 'b' is not of arithmetic type, it is a Boo
test1.d(31): Error: 'a -= b' is not a scalar, it is a Boo
test1.d(31): Error: 'a' is not of arithmetic type, it is a Boo
test1.d(31): Error: 'b' is not of arithmetic type, it is a Boo
----------------------------------------

The overloads of `Boo.foo` are resolved successfully.
This would not be the case if there were method `foo` directly in `Boo`
declaration, because function overloads are not resolved between mixin scope
and the enclosing scope (see e.g. Issue 8228 discussion).

Methods `foo` from the scopes of Plus and Minus are resolved successfully.
However this does not work for `opOpAssign` (and also for opAssign).

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list