[Issue 5886] New: Template this parameter cannot be made implicit, when other parameters are explicitly given
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Apr 25 14:14:12 PDT 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 at puremagic.com
ReportedBy: kennytm at gmail.com
--- Comment #0 from kennytm at 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: -------
More information about the Digitalmars-d-bugs
mailing list