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)

I admit I didn't read the entire description but maybe it is related to this https://d.puremagic.com/issues/show_bug.cgi?id=11954

Reply via email to