byKey and byValue: properties or methods?

Timon Gehr timon.gehr at gmx.ch
Tue Jan 17 16:52:51 PST 2012


On 01/18/2012 01:40 AM, Jonathan M Davis wrote:
> On Tuesday, January 17, 2012 19:31:25 bearophile wrote:
>> Nick Sabalausky:
>>> Without properties, member function access *ANY* many value
>>> accesses are "a.b()". Is this member value a plain-old-var or a
>>> function?
>>> Who knows! It's a leeked out implementation detail, hooray!
>>
>> I have a partially related question.
>>
>> Currently this code compiles even with -property:
>>
>> void main() {
>> int[int] aa = [1:2];
>> auto byval = aa.byValue();
>> }
>>
>> But I think byValue is a property, so isn't it right to give a compilation
>> error if you add () after the name of a property?
>
> Definitely a bug. Strict enforcement requires that parens be used on all
> function calls and that no properties use parens. If you use parens on them,
> that would mean that you're using them on the return value of the property
> (e.g. opCall) - and in fact, that's one of the main reasons that @property was
> added in the first place, since without enforcement, property functions which
> return a delegate result in an ambiguity.
>
> - Jonathan M Davis

A related and way more embarrassing problem is that lazy function 
parameters have the same issue.

This program prints nothing:
import std.stdio;
void foo(lazy void delegate() dg){
     dg();
}
void main(){
     foo({writeln("hello");});
}


More information about the Digitalmars-d mailing list