Thread overview
[Issue 5886] New: Template this parameter cannot be made implicit, when other parameters are explicitly given
Apr 25, 2011
kennytm@gmail.com
Jul 26, 2011
Kenji Hara
Oct 05, 2011
Walter Bright
April 25, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5886

           Summary: Template this parameter cannot be made implicit, when
                    other parameters are explicitly given
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: kennytm@gmail.com


--- Comment #0 from kennytm@gmail.com 2011-04-25 14:10:27 PDT ---
Test case:

--------------------------------------
struct K {
    void get1(this T)() const {
        pragma(msg, T);
    }
    void get2(int N=4, this T)() const {
        pragma(msg, N, " ; ", T);
    }
}

void main() {
    K km;
    const(K) kc;
    immutable(K) ki;
    km.get1;        // OK
    kc.get1;        // OK
    ki.get1;        // OK
    km.get2;        // OK
    kc.get2;        // OK
    ki.get2;        // OK
    km.get2!(1, K);               // Ugly
    kc.get2!(2, const(K));        // Ugly
    ki.get2!(3, immutable(K));    // Ugly
    km.get2!8;    // Error
    kc.get2!9;    // Error
    ki.get2!10;   // Error
}
--------------------------------------
K
const(K)
immutable(K)
4 ; K
4 ; const(K)
4 ; immutable(K)
1 ; K
2 ; const(K)
3 ; immutable(K)
x.d(23): Error: template instance get2!(8) does not match template declaration
get2(int N = 4,this T)
--------------------------------------

The template this parameter is supposed to pick up the type of this at the instantiation site, and should be implicitly defined. But when other template parameters are present, and they are not implicitly determined, the compiler will somehow ignore the fact that T is a TemplateThisParameter, and requires user to fill it out manually.

This also affects operator overloading, e.g.

--------------------------------------
import std.stdio;

struct K {
    int opUnary(string op:"-", this T)() const {
        return 0;
    }
}

void main() {
    K km;
    auto a = -km;  // Error
}
--------------------------------------
x.d(11): Error: template instance opUnary!("-") does not match template
declaration opUnary(string op : "-",this T)
--------------------------------------

I think issue 5393 is a special case of this too.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 26, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5886


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |k.hara.pg@gmail.com


--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2011-07-26 10:16:28 PDT ---
https://github.com/D-Programming-Language/dmd/pull/267

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 05, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5886


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2011-10-04 23:12:32 PDT ---
https://github.com/D-Programming-Language/dmd/commit/804f614e25ac7ff28d481c80e0bd71f65d3a6ec4

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 23, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=5886



--- Comment #3 from github-bugzilla@puremagic.com 2013-04-22 23:55:35 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/4eece51e6368f58b67d3ac3d4f55826dd334a4e4 Additional fix for issue 5886

Even inside member function, implicit TemplateThisParameter should be applied.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------