D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2646 - Named mixins and member functions
Summary: Named mixins and member functions
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-05 12:04 UTC by Max Samukha
Modified: 2019-09-10 09:54 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Max Samukha 2009-02-05 12:04:12 UTC
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 Max Samukha 2009-02-05 12:05:32 UTC
Another try:

template Signal()
{
  void connect() {};
}

class AbstractButton
{
  mixin Signal clicked;
}

class CheckBox : AbstractButton
{
  mixin Signal toggled;
  mixin Signal kicked;
}
Comment 2 Denis Shelomovskii 2012-05-04 07:37:45 UTC
Related NG thread:
http://forum.dlang.org/thread/jo0lmj$4dp$1@digitalmars.com
Comment 3 RazvanN 2019-09-10 09:54:45 UTC
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.