Bug 2646 – Named mixins and member functions

Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-02-05T12:04:12Z
Last change time
2019-09-10T09:54:45Z
Assigned to
No Owner
Creator
Max Samukha

Comments

Comment #0 by samukha — 2009-02-05T12:04:12Z
Functions inserted into a class using named mixins should be considered separate functions. template Signal { void connect(); } class AbstractButton { mixin Signal clicked; } class CheckBox : AbstractButton { mixin Signal toggled; mixin Signal kicked; } CheckBox.toggled.connect shouldn't override AbstractButton.clicked.connect. CheckBox.kicked has nothing to do with AbstractButton.clicked, but currently it causes compilation to fail: "CheckBox.Signal!().connect multiple overrides of same function".
Comment #1 by samukha — 2009-02-05T12:05:32Z
Another try: template Signal() { void connect() {}; } class AbstractButton { mixin Signal clicked; } class CheckBox : AbstractButton { mixin Signal toggled; mixin Signal kicked; }
Comment #2 by verylonglogin.reg — 2012-05-04T07:37:45Z
Comment #3 by razvan.nitu1305 — 2019-09-10T09:54:45Z
Mixin templates are evaluated in the context of the instantiation scope. It doesn't matter if a name is given to it or not. For example: template Signal() { void connect() {}; } class CheckBox { mixin Signal toggled; } void main() { auto a = new CheckBox(); a.connect(); } This code compiles successfully. You don't have to call `a.toggled.connect`. This is possible because connect is inserted in the scope of CheckBox (e.g. in the overload set of that scope level). Changing this would make mixing functions very difficult to work with. Closing as invalid.