Inheritance of mixin

tsbockman via Digitalmars-d digitalmars-d at puremagic.com
Mon May 2 10:50:50 PDT 2016


On Monday, 2 May 2016 at 17:37:14 UTC, Basile B. wrote:
> templatized functions in classes will never be virtual and 
> there's a technical reason explained here:
>
> https://issues.dlang.org/show_bug.cgi?id=1657#c1
>
> (TL;DR: it's problematic to generate the vtbl)

I understand why template methods in general shouldn't be 
virtual. `this T` is special though, and a method with no other 
template parameters could be lowered to an ordinary virtual 
method in a straightforward fashion.

Basically, this:

     class A
     {
         string foo(this T)() { return T.stringof; }
     }

     class B : A { }

Could be lowered to this:

     class A
     {
         string foo() { return A.stringof; }
     }

     class B : A
     {
         override string foo() { return B.stringof; }
     }

That's not how it works currently, but there is no technical 
reason it couldn't be *made* to work that way.

Obviously this would be a breaking change though; `this T` 
template methods that should retain the current behaviour could 
be marked `final`. (Given that non-template methods are virtual 
by default, I think requiring template methods to be marked 
`final` would improve code clarity, anyway.)


More information about the Digitalmars-d mailing list