DIP23 draft: Fixing properties redux

Johannes Pfau nospam at example.com
Sun Feb 3 23:50:28 PST 2013


Am Mon, 04 Feb 2013 04:24:46 +0100
schrieb "TommiT" <tommitissari at hotmail.com>:

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

"getter property of int type"

But a getter shouldn't return void, right? So it's actually not
ambiguous?


More information about the Digitalmars-d mailing list