www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5729] New: taking the address of a property doesn't work

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5729

           Summary: taking the address of a  property doesn't work
           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: mrmocool gmx.de



class A
{
    private int blub = 5;
     property ref int bla()
    {return blub;}
}

void main()
{
    A a = new A();
    int* b = &a.bla;
}

property.d(11): Error: cannot implicitly convert expression (&a.bla) of type
int delegate()  property ref to int*


This only works by adding parentheses: &a.bla()
Shouldn't it work as expected without those for  property methods?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 11 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5729


Harry Vennik <htvennik zonnet.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |htvennik zonnet.nl



---
The point is that you are getting the address of the property function, not the
address of the ref return value. Adding the () changes this, because the () is
evaluated before &.

So the real problem is a syntax ambiguity.

It depends on the context how the reference to the property is evaluated. Try
this:
typeof(a.bla)    // returns  int
typeof(&a.bla)  // returns  int delegate()  property ref

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 01 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5729




---
Really amazing:

typeof(A.bla)      // int
typeof(&A.bla)   // int function()  property ref
typeof(*&A.bla) // int

(The difference with the previous post is that I am referring to class A
instead of its instance a.)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 01 2011