www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12159] New: cannot overload same operator in different mixin templates

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: maximzms gmail.com


--- Comment #0 from Maksim Zholudev <maximzms 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: -------
Feb 14 2014
parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12159


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |DUPLICATE


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2014-02-14
12:59:20 PST ---
Really looks like a duplicate of Issue 11842, but reopen if not.

*** This issue has been marked as a duplicate of issue 11842 ***

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