www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21677] New: Inconsistency on when override is allowed for

https://issues.dlang.org/show_bug.cgi?id=21677

          Issue ID: 21677
           Summary: Inconsistency on when override is allowed for
                    interface methods
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: andrej.mitrovich gmail.com

This might be a dupe.

-----
interface I1 { void foo (); }
interface I2 : I1 {}

void main ()
{
    class C1 : I2
    {
        // fine
        override void foo () { }
    }

    abstract class B : I2 { }

    class C2 : B
    {
        // error?
        override void foo () { }

        // OK:
        // void foo () { }
    }
}
-----

I'm not sure if this is by design, but the compiler seems to disallow using the
`override` keyword for implementing interface methods when there is an
intermediate base class in-between.

It makes it harder to write self-documenting code because I have to get rid of
`override` and then it's not obvious that the method implements something from
the interface.

--
Mar 02 2021