https://issues.dlang.org/show_bug.cgi?id=17714
Issue ID: 17714 Summary: Function template - this T for static methods Product: D Version: D2 Hardware: x86_64 OS: Windows Status: NEW Severity: enhancement Priority: P1 Component: dmd Assignee: nob...@puremagic.com Reporter: timos...@gmail.com For static method templates the this T will not work to deduce the calling derived class/interface. Although this information is present at compile-time, there seems to be no way to easily access the calling derived class: interface I { static void test(this T)() { writeln(T.type.stringof); } } abstract class A { static void test(this T)() { writeln(T.type.stringof); } } class B : A { alias type = uint; } class C : I { alias type = int; } void main() { B.test(); C.test(); } Throws: Error: template app.A.test cannot deduce function from argument types !()(), candidates are: app.A.test(this T)() Error: template app.I.test cannot deduce function from argument types !()(), candidates are: app.I.test(this T)() Shouldn't it be possible to access the class which is calling the static method as easily as "this T" as template parameter? Would "this T" be too confusing, as it is a static method and this does not really exist? To simplify, the following should be possible in some way (if not via "this T"): class A { // T will be whatever class is calling this method static void func (this T)() { }; } A.func(); Possibly related issue: https://issues.dlang.org/show_bug.cgi?id=14191 --