DIP23 draft: Fixing properties redux

Timon Gehr timon.gehr at gmx.ch
Mon Feb 4 06:25:09 PST 2013


On 02/04/2013 03:05 PM, Andrei Alexandrescu wrote:
> ...
> Couldn't AddressOf use "&(" + exp + ")"?
>
> I thought more about this. The problem remains even without @property,
> due to optional parens in function invocation. Consider:
>
> ref int fun() { ... }
> auto p1 = &fun;
> auto p2 = &(fun);
> auto p3 = &(fun());
>
> What are the types of the three? The optional parens in invocation
> require some disambiguation.

The obvious rule is not to give significance to redundant parentheses.

> I think the sensible disambiguation is to
> have &fun take the address of fun and the other two take the address of
> fun's result.
>

No! &fun and &(fun) are the same thing. Functions that get their address 
taken are not implicitly invoked. (Again, Scala agrees.)

The rules are straightforward:

A non- at property function name 'foo' denotes a function invocation 
without arguments iff it does not occur in one of the following contexts:

1. foo(...)          // explicitly called
2. &foo              // address taken
3. ...!(...,foo,...) // template argument (well, that's what DMD 
currently does)
4. alias ... = foo;  // aliased


> I would agree restricting the properties, but requiring a __trait to
> take the address of a regular function or method seems overkill.
>

I have no idea how the conclusion would be reached that this is 
necessary under any of the discussed schemes.



More information about the Digitalmars-d mailing list