Bug 5886 – Template this parameter cannot be made implicit, when other parameters are explicitly given

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-04-25T14:10:00Z
Last change time
2013-04-22T23:55:35Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
kennytm

Comments

Comment #0 by kennytm — 2011-04-25T14:10:27Z
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.
Comment #1 by k.hara.pg — 2011-07-26T10:16:28Z
Comment #2 by bugzilla — 2011-10-04T23:12:32Z
Comment #3 by github-bugzilla — 2013-04-22T23:55:35Z
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.