September 01, 2004 Covariance doesn't work with interfaces | ||||
|---|---|---|---|---|
| ||||
Using DMD 0.100, Windows 98.
For some reason, the principle of covariant return types doesn't extend to implementation of interfaces:
----------
class Yuiop {}
interface Qwert {
Qwert hjkl();
Yuiop zxcvb();
}
class Asdfg : Yuiop, Qwert {
Asdfg hjkl() { return null; }
Asdfg zxcvb() { return null; }
}
----------
D:\My Documents\Programming\D\Tests\bugs\covariant1.d(8): class Asdfg interface function Qwert.hjkl isn't implemented
D:\My Documents\Programming\D\Tests\bugs\covariant1.d(8): class Asdfg interface function Qwert.zxcvb isn't implemented
----------
Further, the fact of a method being part of an interface prevents any covariant overriding in subsequently derived classes:
----------
interface Qwert {
Qwert hjkl();
}
class Asdfg : Qwert {
Qwert hjkl() { return null; }
}
class Qaz : Asdfg {
override Qaz hjkl() { return null; }
}
----------
D:\My Documents\Programming\D\Tests\bugs\covariant2.d(9): class Qaz interface function Qwert.hjkl isn't implemented
D:\My Documents\Programming\D\Tests\bugs\covariant2.d(9): class Qaz interface function Qwert.hjkl isn't implemented
----------
Stewart.
--
My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
| ||||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply