@property Incorrectly Implemented?
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Tue Sep 6 12:57:57 PDT 2016
On 9/6/16 3:18 PM, John wrote:
>
> Currently it seems that @property isn't implemented correctly. For some
> reason when you try to get the pointer of a property it returns a
> delegate for some reason. This just seems plain wrong, the whole purpose
> of a property is for a function to behave as if it weren't a function.
> There's also some inconsistencies in the behavior, "get" is implemented
> one way and then "set" is implemented another.
>
> http://ideone.com/ZgGT2G
>
> &t.x // returns "ref int delegate()"
> &t.x() // ok returns "int*", but defeats purpose of @property
> &(t.j = 10) // shouldn't this return "ref int delegate(int)" ?
>
> It would be nice to get this behavior fixed, so that it doesn't become
> set in stone. I think returning a delegate pointer is not what people
> would except nor is there really any use case for it.
Just FYI, at the moment I believe the only difference (aside from the
defunct -property switch) between a @property function and a
non- at property function is:
int foo1() { return 1; }
@property int foo2() { return 1; }
pragma(msg, typeof(foo1)); // int function()
pragma(msg, typeof(foo2)); // int
That's it. typeof returns a different thing. All @property functions act
just like normal functions when used in all other cases, and property
syntax (assignment and getting) work on non- at property functions.
This situation is less than ideal. But it's been battled about dozens of
times on the forums (including the very reasonable points you are
making). It hasn't been solved, and the cynic in me says it won't ever be.
-Steve
More information about the Digitalmars-d
mailing list