www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14191] New: Failure to locate overload with template this

https://issues.dlang.org/show_bug.cgi?id=14191

          Issue ID: 14191
           Summary: Failure to locate overload with template this
                    parameter
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: blocker
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: blah38621 gmail.com

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.

--
Feb 16 2015