Using ()s in @property functions

Rainer Deyke rainerd at eldwood.com
Mon Jun 28 21:02:32 PDT 2010


On 6/28/2010 20:40, dsimcha wrote:
> Once enforcement of @property is enabled, we need to decide whether calling an
> @property function using ()s should be legal.

No, "we" don't.  Walter does.


>  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.
> }

Allowing parentheses also leads to ambiguity:

  struct Foo {
      uint num;

      @property int delegate() front() {
          return delegate (){ return 5; };
      }
  }


  void main() {
      Foo foo;
      auto bar = foo.front();  // What is the type of 'bar'?
  }

The problem is that 'front' refers to two things: the property and its
accessor function.  So long as this is the case, ambiguity is unavoidable.


-- 
Rainer Deyke - rainerd at eldwood.com


More information about the Digitalmars-d mailing list