Comment #0 by matti.niemenmaa+dbugzilla — 2006-11-18T09:30:36Z
class Base {
final void foo() {}
}
class Derived : Base {
void foo() {}
}
This compiles fine, although "Functions marked as final may not be overridden in a derived class".
Changing Derived.foo to override void foo() {} makes DMD bark:
asdf.d(7): function asdf.Derived.foo function foo does not override any
With or without override, DMD should say "function asdf.Derived.foo cannot override final function asdf.Base.foo" or something to that effect.
Comment #1 by bruno.do.medeiros+deebugz — 2006-11-21T18:00:17Z
>This compiles fine, although "Functions marked as final may not be overridden
>in a derived class".
And it does not override, due to the presence of 'final'. It creates a new method lineage, similar to C# 'new' in a method declaration, thus 'final' does have an effect on methods. If it's the best behavior that's another story, but it's not against the spec I believe.
Comment #2 by matti.niemenmaa+dbugzilla — 2006-12-03T05:03:07Z
It is against the spec. See http://www.digitalmars.com/d/function.html, under "Virtual Functions": "Functions marked as final may not be overridden in a derived class, unless they are also private. For example:"
class A
{
int def() { ... }
final int foo() { ... }
final private int bar() { ... }
private int abc() { ... }
}
class B : A
{
int def() { ... } // ok, overrides A.def
int foo() { ... } // error, A.foo is final
int bar() { ... } // ok, A.bar is final private, but not virtual
int abc() { ... } // ok, A.abc is not virtual, B.abc is virtual
}
The relevant bit is the comment "error, A.foo is final". This code compiles without a problem, yet according to the spec it shouldn't.