Bug 2252 – Sequence of super interfaces matters

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2008-07-29T18:50:34Z
Last change time
2019-09-09T14:34:24Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Frank Benoit

Comments

Comment #0 by benoit — 2008-07-29T18:50:34Z
import std.stdio; version=PROBLEM; interface I1 { void foo(); } interface IConsts { } version(PROBLEM){ interface I2 : IConsts, I1 { void bar(); } } else{ interface I2 : I1, IConsts { void bar(); } } class C1 : I1 { void foo() { writefln("foo"); } } class C2 : C1, I2 { void bar() { writefln("bar"); } void bar2() { writefln("bar"); } } void main() { C2 c2 = new C2(); c2.foo(); c2.bar(); } //------------------------------------- If version=PROBLEM is set, the error given is: class t.C2 interface function I1.foo is not implemented
Comment #1 by 2korden — 2008-07-29T19:04:33Z
The following example has no workaround: import std.stdio; interface I1 { void foo1(); } interface I2 { void foo2(); } interface I3 : I1, I2 { void bar(); } class C1 : I1, I2 { void foo1() { writefln("foo1"); } void foo2() { writefln("foo2"); } } class C2 : C1, I3 { void bar() { writefln("bar"); } } void main() { C2 c2 = new C2(); c2.foo1(); c2.foo2(); c2.bar(); }
Comment #2 by 2korden — 2008-07-29T19:25:26Z
Just to make it more clear: last example produces the following error message: test.d(20): class test.C2 interface function I2.foo2 is not implemented because of this line: interface I3 : I1, I2 { /* ... */ } I1 somehow shadows I2 and its implementation is not found in C2. exchanging an interface declaration order: interface I3 : I2, I1 { /* ... */ } unhides I2 implementation but hides I1's one: test.d(20): class test.C2 interface function I1.foo1 is not implemented.
Comment #3 by smjg — 2008-11-24T08:24:13Z
ISTM the bug is actually that the original code compiles without version=PROBLEM, rather than that it fails with. http://www.digitalmars.com/d/1.0/interface.html "A reimplemented interface must implement all the interface functions, it does not inherit them from a super class" C2 reimplements I1, albeit indirectly. So the code should be class C2 : C1, I2 { void foo() { super.foo(); } void bar() { writefln("bar"); } void bar2() { writefln("bar"); } } You could argue that indirect reimplementation should be exempt from this requirement, but that would be an enhancement request.
Comment #4 by verylonglogin.reg — 2014-07-19T14:57:46Z
(In reply to Stewart Gordon from comment #3) > ISTM the bug is actually that the original code compiles without > version=PROBLEM, rather than that it fails with. > [snip] > "A reimplemented interface must implement all the interface functions, it > does not inherit them from a super class" > [snip] So this code should NOT compile: --- interface I1 { void f(); } interface I2: I1 { } class C1: I1 { void f() { } } class C2: C1, I2 { } // fails for I1 ---
Comment #5 by razvan.nitu1305 — 2019-09-09T14:34:24Z
This is the intended behavior. Closing as invalid.