Bug 14191 – Failure to locate overload with template this parameter

Status
RESOLVED
Resolution
DUPLICATE
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-02-17T03:46:48Z
Last change time
2018-03-09T19:06:07Z
Assigned to
No Owner
Creator
Orvid King
See also
https://issues.dlang.org/show_bug.cgi?id=17714, https://issues.dlang.org/show_bug.cgi?id=17713

Comments

Comment #0 by blah38621 — 2015-02-17T03:46:48Z
The following code fails to compile with: Error: template main.C.myTemplate2 cannot deduce function from argument types !()(int), candidates are: main.C.myTemplate2(this P, T)(T val) And the code: void main(string[] args) { D.myTemplate3(0); } class C { static void myTemplate2(this P, T)(T val) { P.myTemplate(val); } } class D : C { static void myTemplate3(T)(T val) { myTemplate2(val); } static void myTemplate(T)(T val) { } } Removing `this P` from the template parameter list of `myTemplate2` allows it to compile, but doesn't give access to `myTemplate`. This makes it very difficult to abstract out templated code into a base class that is dependent upon the implementation in the derived class.
Comment #1 by nick — 2018-03-09T19:06:07Z
The spec says: "TemplateThisParameters are used in member function templates to pick up the type of the this reference." Using them in static methods is an enhancement, so this is a duplicate. *** This issue has been marked as a duplicate of issue 10488 ***