www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12230] New: properties do not bind templates via alias parameter

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: thecybershadow gmail.com



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: -------
Feb 23 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12230


Vladimir Panteleev <thecybershadow gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|properties do not bind      |methods do not bind
                   |templates via alias         |templates via alias
                   |parameter                   |parameter



11:51:47 EET ---
Actually, this refers to all non-static methods, not just properties.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 23 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12230


Vladimir Panteleev <thecybershadow gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull



22:32:27 EET ---
https://github.com/D-Programming-Language/dmd/pull/3345

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 02 2014