Bug 559 – Final has no effect on methods

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-11-18T09:30:00Z
Last change time
2014-02-15T13:21:59Z
Keywords
accepts-invalid, diagnostic, spec
Assigned to
bugzilla
Creator
matti.niemenmaa+dbugzilla
Blocks
511

Comments

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.
Comment #3 by bugzilla — 2007-07-01T13:26:05Z
Fixed DMD 1.018 and DMD 2.002
Comment #4 by thomas-dloop — 2007-07-23T14:56:52Z