Using ()s in @property functions

Jonathan M Davis jmdavisprog at gmail.com
Tue Jun 29 11:38:42 PDT 2010


On Monday, June 28, 2010 19:40:06 dsimcha wrote:
> Once enforcement of @property is enabled, we need to decide whether calling
> an @property function using ()s should be legal.  In other words, should
> @property **require** omission of ()s or just allow it?  My vote is for
> just allowing omission, because I've run into the following ambiguity
> while debugging std.range.  Here's a reduced test case:
> 
> struct Foo {
>     uint num;
> 
>     @property ref uint front() {
>         return num;
>     }
> }
> 
> void main() {
>     Foo foo;
>     uint* bar = &foo.front;  // Tries to return a delegate.
> }
> 
> If I can assume that @property functions can be called with explicit ()s to
> forcibly disambiguate this situation, then I can fix these kinds of bugs by
> simply doing a:
> 
> uint* bar = &(foo.front());
> 
> Can we finalize the idea that this will continue to be allowed now so that
> I can fix the relevant bugs in Phobos and know that my fix won't be broken
> in a few compiler releases?

FWIW, TDPL says that you can't use the parens when using a property function.

- Jonathan M Davis


More information about the Digitalmars-d mailing list