Bug 10912 – property overridding requires both accessors to be overridden

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-27T11:37:00Z
Last change time
2013-08-27T19:42:59Z
Assigned to
nobody
Creator
burg.basile

Comments

Comment #0 by burg.basile — 2013-08-27T11:37:05Z
When overriding a property setter in a descendant class, the getter must also be overridden (or explicitly called with super), otherwise the compiler doesnt understand we want to call the getter. example: --- import std.stdio; class foo { private int fMyField; public: @property { void MyField(int aValue){fMyField = aValue;} int MyField(){return fMyField;} } } class bar: foo { public: @property { override void MyField(int aValue){fMyField = 0;} } this() { writeln(MyField());// dmd should detect that the getter exists in foo. writeln(super.MyField());//super. would be superfluous } } void main(string[] args) { auto Bar = new bar; } --- result: compile-time error, "Error: function f337.bar.MyField (int aValue) is not callable using argument types ()"
Comment #1 by andrej.mitrovich — 2013-08-27T19:42:59Z
Use: alias super.MyField MyField; in the 'bar' class. When you override only one overload of a function, the other functions are hidden, unless you re-introduce the overloadset to the subclass. This is related to function hijacking, which you can read about here: http://dlang.org/hijack.html Although that page seems to miss the information about using 'alias super.name name' for subclasses, it should probably be filed as a website bug.