Bug 5729 – taking the address of a @property doesn't work

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-03-11T08:50:00Z
Last change time
2014-03-28T20:57:12Z
Keywords
rejects-valid
Assigned to
nobody
Creator
hoganmeier

Comments

Comment #0 by hoganmeier — 2011-03-11T08:50:19Z
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?
Comment #1 by htvennik — 2011-04-01T09:32:40Z
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
Comment #2 by htvennik — 2011-04-01T09:42:57Z
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.)
Comment #3 by lt.infiltrator — 2014-03-19T16:43:45Z
&a.bla correctly gets the address of the function. If this were changed for @properties only, as you seem to suggest, then how would one go about getting the address of the actual function? It would also lead to different semantics from the same syntax depending on whether the function were marked @property, which is highly undesirable (do you want to go check the class definition every time you want to get an address?)
Comment #4 by k.hara.pg — 2014-03-28T20:57:12Z
(In reply to comment #3) > &a.bla correctly gets the address of the function. If this were changed for > @properties only, as you seem to suggest, then how would one go about getting > the address of the actual function? It would also lead to different semantics > from the same syntax depending on whether the function were marked @property, > which is highly undesirable (do you want to go check the class definition every > time you want to get an address?) I agree with this argument.