digitalmars.D - mixin templates and classes
- Denis Shelomovskij (47/47) May 04 2012 IMHO this should compile:
IMHO this should compile: --- mixin template T() { final void f() { } } class A { mixin T ta; } class B : A { mixin T tb; } --- these asserts should pass: --- mixin template T(string s) { string f() { return s; } } class A { mixin T!"T1" ta1; mixin T!"T2" ta2; mixin T!"T"; } class B : A { override string f() { return "B"; } } void main() { assert((new B).f() == "B"); assert((new B).ta1.f() == "T1"); // Fails: ta1.f() = "B" assert((new B).ta2.f() == "T2"); // Doesn't compile because of Issue 8033 // Will fail once will compile: (new A).f() = "T" // assert((new A).f() == "B"); } --- and this should not compile (Issue 8034): --- mixin template T(string s) { string f() { return s; } } class A { mixin T!"T1" ta1; mixin T!"T2" ta2; } class B : A { override string f() { return "B"; } } --- And I see one easy way to improve the situation: disallow named template mixins to override/add virtual methods except a destructor. Thoughts? -- Денис В. Шеломовский Denis V. Shelomovskij
May 04 2012