On Friday, 7 March 2014 at 06:23:58 UTC, Frustrated wrote:
Can someone check this out? The best I can acertain is that the mixin template isn't adding the generated functions because it thinks they are already in the class.

i.e., the code generates the following methods

@property iButton button(iButton b)
@property iBorder border(iBorder b)

and the class contains the methods

@property WindowsButton button()
@property WindowsButton button(WindowsButton b)

and the template mixin simply doesn't add the generic methods. (simply because mixing the string mixin directly works, wrapping it in a mixin template does not)

Using that I created a MWE:

http://dpaste.dzfl.pl/6f64e49aba95



import std.stdio, std.cstream;

// mixin template used to wrap the string mixin
mixin template C() { mixin(B); }

// eponymously named template used as a string mixin to generate the function
template B()
{
string B() { return "void foo(iA a) { writeln(`Generic`); }"; }
}

interface iA {  void foo(iA a); }

class A : iA
{
        void foo(A a) { writeln("Specific"); }
        //mixin(B);
mixin C; // doesn't work, use line above, does not insert generic foo
}


void main()
{
        iA a = new A;
        a.foo(a);
        (cast(A)a).foo(cast(A)a);
(cast(A)a).foo(a); // line doesn't work when using mixin template because the generic foo does not exist
}


This seems like a bug to me but maybe that's how mixin templates work? If so is there any way to make them insert the code regardless if it thinks they are the same? (they are not in this case and I need to use them to reduce redundancy)

functions introduced through mixin templates do not take part in overload resolution when an overload exists outside the mixin. It's a common annoyance, I can't remember if there's a good reason for it.

Reply via email to