[Issue 16318] inherit from interface via abstract class

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Aug 12 07:13:07 PDT 2016


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

b2.temp at gmx.com changed:

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

--- Comment #3 from b2.temp at gmx.com ---
(In reply to Lodovico Giaretta from comment #2)
> (In reply to b2.temp from comment #1)
> > Your request is not valid because it already works. You forget that an
> > interface method has to be implemented at least once before being
> > overridden, otherwise what do you override ? An interface method is not like
> > an abstract method and the error message couldn't be more accurate.
> 
> Sorry, I don't understand your reasoning, so I'd love if you could answer
> the following points. Thank you in advance for spending your time on this.
> 
> If I inherit directly from an interface, I can override:
> 
> ==================
> interface IFoo { void foo(); }
> 
> class FooImpl: IFoo { override void foo(); } // override here is fine

I suspect this usage of "override" of being an noop.
We need an exact analysis from a DMD expert here.

> ==================
> 
> It seems counterintuitive that you can't do this transitively:
> 
> ==================
> interface IFoo { void foo(); }
> 
> abstract class AFoo: IFoo {}
> 
> class FooImpl: AFoo { override void foo(); } // override here does not work
> ==================
> 
> It is true that it works if I remove "override", but this makes it unclear
> that FooImpl.foo overrides IFoo.foo. 

FooImpl.foo doesn't **override** IFoo.foo, it **implements** IFOO.foo.

The compiler will throw an error if you forget. Here you argument is really a
matter of taste. I can say that what makes unclear that IFOO is implemented
because an abstract class is used in the middle.

> When I encountered this, it made me
> think that FooImpl.foo was just hiding IFoo.foo because of some signature
> error I did.

Anyway, it's a DUP

*** This issue has been marked as a duplicate of issue 2525 ***

--


More information about the Digitalmars-d-bugs mailing list