Bug in D!!!

Jesse Phillips via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 1 16:25:04 PDT 2017


I've love being able to inherit and override generic functions in 
C#. Unfortunately C# doesn't use templates and I hit so many 
other issues where Generics just suck.

I don't think it is appropriate to dismiss the need for the 
compiler to generate a virtual function for every instantiated T, 
after all, the compiler can't know you have a finite known set of 
T unless you tell it.

But lets assume we've told the compiler that it is compiling all 
the source code and it does not need to compile for future 
linking.

First the compiler will need to make sure all virtual functions 
can be generated for the derived classes. In this case the 
compiler must note the template function and validate all derived 
classes include it. That was easy.

Next up each instantiation of the function needs a new v-table 
entry in all derived classes. Current compiler implementation 
will compile each module independently of each other; so this 
feature could be specified to work within the same module or new 
semantics can be written up of how the compiler modifies already 
compiled modules and those which reference the compiled modules 
(the object sizes would be changing due to the v-table 
modifications)

With those three simple changes to the language I think that this 
feature will work for every T.


More information about the Digitalmars-d-learn mailing list