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: [email protected]
ReportedBy: [email protected]
--- Comment #0 from Vladimir Panteleev <[email protected]> 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: -------