UFCS & overloaded property getters/setters
Shammah Chancellor via Digitalmars-d
digitalmars-d at puremagic.com
Fri Jun 13 14:16:36 PDT 2014
On 2014-06-13 16:39:04 +0000, H. S. Teoh via Digitalmars-d said:
>
> Basically, once the derived class overrides the property setter, the
> (un-overridden) base class getter somehow becomes shadowed as well, and
> references to .prop will cause a compile error saying that Derived.prop
> can't be called without parameters.
>
> So, what's going on here? Should this code be accepted? Is this a
> compiler / language bug? A deliberate @property limitation? Or just more
> evidence @property should be taken out the back and shot?
>
>
> T
I had absolutely no problems with the following code. Note where and
how the alias for prop is located.
import std.stdio;
class Base {
int propImpl;
final @property int prop() { writefln("hihihi!");
return propImpl; }
@property void prop(int newVal) { propImpl = newVal; }
void someMethod() {
auto x = prop; // OK, calls Base.prop()
prop = x; // OK, calls Base.prop(int)
}
}
class Derived : Base {
alias prop = super.prop;
override @property void prop(int newVal) {
super.prop(newVal);
writefln("Hello!");
}
void someOtherMethod() {
auto x = prop; // NG - compile error ***
auto y = super.prop; // OK, calls Base.prop()
prop = x; // OK, calls Derived.prop()
}
}
void main() {
auto foo = new Derived();
foo.someOtherMethod();
}
More information about the Digitalmars-d
mailing list