Bug 5046 – Wrong type of implicit 'this' in struct/class templates
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2010-10-12T15:28:00Z
Last change time
2011-07-18T20:17:45Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
rsinfu
Comments
Comment #0 by rsinfu — 2010-10-12T15:28:10Z
Implicit 'this' references in struct/class templates are wrongly typed under certain circumstance and the following code doesn't compile.
--------------------
void main()
{
auto va = S!("", int)();
auto vb = makeS!("", int)();
}
struct S(alias p, T)
{
T s;
T fun() { return s; } // (10)
}
S!(p, T) makeS(alias p, T)()
{
return typeof(return)();
}
--------------------
% dmd -o- -c test.d
test.d(10): Error: this for s needs to be type S not type S!("",int)
--------------------
The error does not happen if
- Either va or vb is commented out,
- Template parameter "alias p" is replaced with "string p", or
- "return s" at line (10) is replaced with "return this.s".
The Sequence struct in std.range hits this problem. It currently works around the problem by supplying explicit 'this' to all fields.