digitalmars.D.bugs - [Issue 20816] New: this template parameter does not work on static
- d-bugmail puremagic.com (56/56) May 09 2020 https://issues.dlang.org/show_bug.cgi?id=20816
https://issues.dlang.org/show_bug.cgi?id=20816 Issue ID: 20816 Summary: this template parameter does not work on static method Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: enhancement Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: destructionator gmail.com Consider the following: --- class A { static void one() { pragma(msg, typeof(this)); } static void two(this This)() { } } void main() { A.one(); A.two(); } --- It currently does: $ dmd pow A pow.d(13): Error: template pow.A.two cannot deduce function from argument types !()(), candidates are: pow.d(6): two(this This)() (please note it does the same thing if I use an A instance instead of the type specifically, e.g. `A a; a.one(); a.two();` does the same error.) I vacillated on if this is a bug or if it isn't supposed to work at all. The spec says: "TemplateThisParameters are used in member function templates to pick up the type of the this reference." Now, you're probably thinking "lol silly adam, it is static so there is no `this` reference". But that's why I put the method `one` in there - there is a `this` reference and the compiler knows its type in the normal case. Of course *using* the `this` reference yields the error "this is only defined in non-static member functions", so I grant there is some ambiguity, but the type does clearly exist and the template is really only interested in that static type. Moreover, precisely because template this parameters work strictly via the static type anyway, it needs no dynamic information so there's no theoretical reason I can think of why it shouldn't work. Thus, since the spec is silent on there existing any other exceptions to the rule, I deem that this *should* work per the spec and thus qualifies as an implementation issue, though since there is some ambiguity in the precise meaning of "this reference" in the spec text, I classified it as an enhancement rather than a normal bug per se. Note that if there were `class B : A {}`, then `B.two();` should also work and `is(This == B)` ought to pass inside the `A.two` template implementation. --
May 09 2020