mixin bug?
Engine Machine via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Aug 11 10:56:47 PDT 2016
template F1(T)
{
void bar() { writeln("Bar0"); }
}
template F2(T)
{
mixin F1!T;
void foo() { bar(); }
}
template F3(T)
{
mixin F2!T;
void bar() { writeln("Bar1"); } // <- This bar should be used
for F2's foo!
}
struct F4(T)
{
mixin F3!T;
}
(Or on can turn F3 in to a struct directly)
Then f3.foo() calls bar from F0, not F3's bar! This seems like a
big bug! One expects the same behavior of mixins regardless of
mixin nesting.
While you could argue that foo, when declared, is calling F0's
bar, this is not consistent with the view that mixin templates
only adds what is not there. I don't like the idea that calls are
resolved first come first serve as it means one can't extend
templates in a natural logical way.
More information about the Digitalmars-d-learn
mailing list