DIP23 draft: Fixing properties redux
Timon Gehr
timon.gehr at gmx.ch
Mon Feb 4 05:20:09 PST 2013
On 02/04/2013 04:24 AM, TommiT wrote:
> On Monday, 4 February 2013 at 02:36:41 UTC, Timon Gehr wrote:
>> On 02/04/2013 03:23 AM, kenji hara wrote:
>>> Unfortunately, I can present a counterexample.
>>>
>>> struct S {
>>> static int value;
>>> static @property int foo() { return value; }
>>> static @property void foo(int n) { value = n; }
>>>
>>> }
>>> void main() {
>>> int n = S.foo;
>>> S.foo = 1;
>>> }
>>>
>>> Should they be disallowed, as like module level properties?
>>>
>>> Kenji Hara
>>
>> Probably. (static essentially means module-level, but in a potentially
>> nested name space.)
>
> I disagree.
Well, it is what the proposal says.
> Static properties can be allowed because they're not
> ambiguous. The problem with module-level:
> @property void foo(int n) {}
> ...are the two interpretations of foo as either a setter taking an int
> or a getter property of int type. So, one of those interpretations must
> be disallowed. But, with static member properties, there aren't multiple
> interpretations.
You are right.
More information about the Digitalmars-d
mailing list