Bug 8228 – Mixin template can't add constructor to class
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-06-11T15:22:20Z
Last change time
2020-09-17T21:31:29Z
Assigned to
No Owner
Creator
Andrej Mitrovic
Comments
Comment #0 by andrej.mitrovich — 2012-06-11T15:22:20Z
mixin template Root()
{
this(int x) { }
void test() { }
}
class Foo
{
mixin Root;
this()
{
test(); // OK
this(1); // FAIL
}
}
void main() { }
It's ok to add virtual methods but not constructors. This has to be a bug..
Comment #1 by john.loughran.colvin — 2013-08-21T15:16:42Z
(In reply to comment #0)
> mixin template Root()
> {
> this(int x) { }
> void test() { }
> }
>
> class Foo
> {
> mixin Root;
> this()
> {
> test(); // OK
> this(1); // FAIL
> }
> }
>
> void main() { }
>
> It's ok to add virtual methods but not constructors. This has to be a bug..
sadly, it's not a bug. template mixins create a scope and there's no overload resolution between it and it's enclosing scope.
We should really have a way of doing a full mixin without resorting to strings.
Comment #2 by andrej.mitrovich — 2013-08-21T15:26:31Z
*** Issue 9851 has been marked as a duplicate of this issue. ***
Comment #3 by andrej.mitrovich — 2016-08-27T22:43:49Z
Indeed this is not technically a bug at all, for example:
http://dlang.org/spec/template-mixin.html#mixin_scope
*However*, we could make it a compiler error to define constructors in mixin templates as they can't really be used in any way.
Comment #4 by simen.kjaras — 2020-09-17T21:31:29Z
*** This issue has been marked as a duplicate of issue 3332 ***