Comment #0 by bearophile_hugs — 2010-08-19T06:22:41Z
This D2 program compiles and runs with DMD 2.048 with no errors:
import std.c.stdio: puts;
class Base {
this() { foo(); }
private void foo() { puts("Base.foo"); } // called
}
class Derived : Base {
private override void foo() { // not called
puts("Derived.foo");
super.foo();
}
}
void main() {
auto d = new Derived();
}
Output:
Base.foo
If Base.foo() is private then it's final. Then what is Derived.foo() overriding?
Comment #1 by issues.dlang — 2010-08-19T15:39:49Z
The fact that private has anything to do with final is arguably a bug. It certainly contradicts TDPL. The bug on that is http://d.puremagic.com/issues/show_bug.cgi?id=4542
Now, this is still a bug. Either dmd still makes private final, at which point overriding the method should be a bug, or it follows TDPL and does not make it final, at which point, the derived method should be called, which it isn't. So, this is a definitely a bug, but I'd favor fixing #4542 and make it call the derived method rather than making overriding the method an error.
Comment #2 by andrej.mitrovich — 2012-10-21T21:28:55Z
Private methods are now final by default and OP sample errors. Whether or not that will change (probably not) depends on Issue 4542.