properties
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Jul 28 08:37:05 PDT 2009
Michel Fortin wrote:
> On 2009-07-28 10:16:16 -0400, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> said:
>
>> Well I don't think so. To repeat what I wrote elsethread: foo = bar is
>> rewritten into foo(bar) if and only if auto __x = foo, __x = bar
>> works. This means, a setter only works if there's a corresponding
>> getter. (Write-only properties be damned.)
>
> This may lead to strange issues if both the setter and the getter don't
> have the same protection attribute, or purity, or constness of arguments.
>
> For instance:
>
> protected void foo(Object o);
> public pure const const(Object) foo();
>
> Here, you can assign to foo using the property syntax only from a
> non-pure functions of this class or a derived classes and when the value
> you're assinging is a const(Object). Elsewhere, you can only assign
> using the function syntax. Anything else would break "auto __x = foo,
> __x = bar".
Well I chose the rule that makes bar look and feel as much as an
assignable value as possible. The rule could be relaxed (e.g. by
dropping qualifiers), but that means we're departing from assignable
value lookalike.
Andrei
More information about the Digitalmars-d
mailing list