UFCS & overloaded property getters/setters

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 13 09:39:04 PDT 2014


I'm not sure if this is a bug, or an anti-pattern, or what, but I ran
into this issue yesterday:

	class Base {
		int propImpl;
		final @property int prop() { 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 {
		override @property void prop(int newVal) {
			super.prop(newVal);
			doSomethingElse(newVal);
		}

		void someOtherMethod() {
			auto x = prop; // NG - compile error ***
			auto y = super.prop; // OK, calls Base.prop()
			prop = x; // OK, calls Derived.prop()
		}
	}

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

-- 
This sentence is false.


More information about the Digitalmars-d mailing list