property syntax strawman
Michiel Helvensteijn
m.helvensteijn.remove at gmail.com
Sun Aug 2 10:22:05 PDT 2009
Andrei Alexandrescu wrote:
> Then in a later message you mention:
>
> bool empty.get() { ... }
> void empty.set(bool b) { ... }
>
> which I like and which does not seem to have difficulties; the names
> "get" and "set" will be never used as such.
Yes, those are two notations for the same thing, and they have the same
problem. Let me demonstrate:
--------------------------------------------------
struct S {
int get() { return 42; }
};
struct T {
S _s;
S property.get() { return _s; }
void property.set(S s) { _s = s; }
}
T t;
auto X = t.property.get();
--------------------------------------------------
What is the type of X? It can be either S or int, depending on how D handles
the situation.
The ambiguity is in the possibility to directly reference the getter and
setter methods. In that other subthread (the older one) I listed some
possible solutions.
The first is to make such a program an error.
The second is not to allow a direct reference to a getter/setter (so X is an
int).
The third is to let the getter/setter overshadow S members (so X is an S).
--
Michiel Helvensteijn
More information about the Digitalmars-d
mailing list