If your interface has a method whose return type is another interface, covariance won't work. sample code: <code> interface Iface1 { Iface2 func1(); } interface Iface2 { Iface1 func2(); } class C1 : Iface1 { C2 func1(){ return null; } } class C2 : Iface2 { C1 func2(){ return null; } } void main() { } </code> when building, I get: main.d(13): function main.C1.func1 of type C2() overrides but is not covariant with main.Iface1.func1 of type Iface2() Here, interface Iface1 declares a method func1 of type Iface2. We have a class C2 which implements Iface2, and a class C1 which implements Iface1. If we try to implement func1 in C1 with a return type of C2, the compiler complains that this return type is not covariant with Iface2, even though C2 does implement Iface2. if instead we implement Iface1 and Iface2 in one class, eveything works properly. The following example produces no errors. <code> interface Iface1 { Iface2 func1(); } interface Iface2 { Iface1 func2(); } class C : Iface1, Iface2 { C func1(){ return null; } C func2(){ return null; } } void main() { } </code>
(In reply to comment #0) > If your interface has a method whose return type is another interface, > covariance won't work. Actually, the failure of your code has nothing to do with the fact that they're interfaces. It's a case of a bug I've noticed before, whereby covariance fails if the return type is forward referenced. For a real instance of what you've written in your first sentence, see issue 210.
Fixed DMD 0.162
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル