www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5886] New: Template this parameter cannot be made implicit, when other parameters are explicitly given

reply d-bugmail puremagic.com writes:
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



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: -------
Apr 25 2011
next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Jul 26 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Oct 04 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5886




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: -------
Apr 22 2013