[Issue 12230] New: properties do not bind templates via alias parameter
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Feb 23 01:49:13 PST 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12230
Summary: properties do not bind templates via alias parameter
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: thecybershadow at gmail.com
--- Comment #0 from Vladimir Panteleev <thecybershadow at gmail.com> 2014-02-23 11:49:08 EET ---
///////////////////// test.d ////////////////////
import std.stdio;
static template T(alias a)
{
void foo() { writeln(a); }
}
struct S
{
int i = 1;
@property int p() { return 2; }
alias ti = T!i; // OK
alias tp = T!p; // Error
}
/////////////////////////////////////////////////
The compiler rejects the above code, with the error:
test.d(5,23): Error: need 'this' for 'p' of type '@property int()'
The problem can be worked around by adding an anchor parameter to the template.
This correctly sets the "this" type for the template:
//////////////////// test2.d ////////////////////
static template T(alias a, alias anchor = Object)
{
void foo() { writeln(a); }
}
struct S
{
int i = 1;
@property int p() { return 2; }
alias ti = T!(i); // bound to S implicitly
alias tp = T!(p, i); // bound to S via anchor
}
/////////////////////////////////////////////////
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list