D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8228 - Mixin template can't add constructor to class
Summary: Mixin template can't add constructor to class
Status: RESOLVED DUPLICATE of issue 3332
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
: 9851 (view as issue list)
Depends on:
Blocks:
 
Reported: 2012-06-11 15:22 UTC by Andrej Mitrovic
Modified: 2020-09-17 21:31 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2012-06-11 15:22:20 UTC
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 John Colvin 2013-08-21 15:16:42 UTC
(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 Andrej Mitrovic 2013-08-21 15:26:31 UTC
*** Issue 9851 has been marked as a duplicate of this issue. ***
Comment 3 Andrej Mitrovic 2016-08-27 22:43:49 UTC
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 Simen Kjaeraas 2020-09-17 21:31:29 UTC

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