www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 559] New: Final has no effect on methods

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=559

           Summary: Final has no effect on methods
           Product: D
           Version: 0.174
          Platform: PC
               URL: http://www.digitalmars.com/d/function.html
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid, diagnostic
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: deewiant gmail.com


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.


-- 
Nov 18 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=559






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 have an effect on methods. If it's the best behavior that's another story, but it's not against the spec I believe. --
Nov 21 2006
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=559


deewiant gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
OtherBugsDependingO|                            |511
              nThis|                            |
           Keywords|                            |spec





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.


-- 
Dec 03 2006
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=559


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





Fixed DMD 1.018 and DMD 2.002


-- 
Jul 01 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=559






test case:
http://dstress.kuehne.cn/nocompile/final_01.d


-- 
Jul 23 2007