5046 – Wrong type of implicit 'this' in struct/class templates

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5046 - Wrong type of implicit 'this' in struct/class templates
Summary: Wrong type of implicit 'this' in struct/class templates
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 All
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
Reported: 2010年10月12日 15:28 UTC by Shin Fujishiro
Modified: 2011年07月18日 20:17 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Shin Fujishiro 2010年10月12日 15:28:10 UTC
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.
Comment 1 Kenji Hara 2011年07月14日 04:22:25 UTC
https://github.com/D-Programming-Language/dmd/pull/94 


AltStyle によって変換されたページ (->オリジナル) /