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();
}