Bug 12159 – cannot overload same operator in different mixin templates

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-02-14T05:12:00Z
Last change time
2014-02-14T12:59:20Z
Assigned to
nobody
Creator
maximzms

Comments

Comment #0 by maximzms — 2014-02-14T05:12:34Z
---------------------------------------- // 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).
Comment #1 by andrej.mitrovich — 2014-02-14T12:59:20Z
Really looks like a duplicate of Issue 11842, but reopen if not. *** This issue has been marked as a duplicate of issue 11842 ***