August 27, 2013 [Issue 10912] New: property overridding requires both accessors to be overridden | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=10912 Summary: property overridding requires both accessors to be overridden Product: D Version: D2 Platform: All URL: http://dpaste.dzfl.pl/7bd529ae OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: burg.basile@yahoo.com --- Comment #0 from burg.basile@yahoo.com 2013-08-27 11:37:05 PDT --- 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 ()" -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
August 28, 2013 [Issue 10912] property overridding requires both accessors to be overridden | ||||
---|---|---|---|---|
| ||||
Posted in reply to burg.basile@yahoo.com | http://d.puremagic.com/issues/show_bug.cgi?id=10912 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |andrej.mitrovich@gmail.com Resolution| |INVALID --- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-08-27 19:42:59 PDT --- 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation