auto return type inheritance not covariant
Maybe this has been brought up before, but i could find no previous submissions. the following code compiles with the error Error: function xxx.B.fn of type () overrides but is not covariant with xxx.A.fn of type () even though they both return an auto of type int... is this a bug or oversight by myself? I am unable to find any documentation saying that this is illegal. I realize its easy to fix by changing the return type to int, however i was just curious. class A { auto fn() { return 10; } } class B : A { auto fn() { return 5; } }
Re: auto return type inheritance not covariant
On Wednesday, February 02, 2011 15:31:02 iLewis wrote: Maybe this has been brought up before, but i could find no previous submissions. the following code compiles with the error Error: function xxx.B.fn of type () overrides but is not covariant with xxx.A.fn of type () even though they both return an auto of type int... is this a bug or oversight by myself? I am unable to find any documentation saying that this is illegal. I realize its easy to fix by changing the return type to int, however i was just curious. class A { auto fn() { return 10; } } class B : A { auto fn() { return 5; } } I'm not aware of a bug report on the matter. You should create one at http://d.puremagic.com/issues . Also, this list is not really intended to be posted to. It's for seeing the messages about changes to bug reports which the tracker sends. If you want to post questions, they should generally go to D.Learn or D. - Jonathan M Davis
Re: auto return type inheritance not covariant
iLewis: Maybe this has been brought up before, but i could find no previous submissions. It looks like a bug fit for Bugzilla: class Foo { int fun1() { return 1; } auto fun2() { return 1; } auto fun3() { return 1; } } class Bar : Foo { override auto fun1() { return 1; } override int fun2() { return 1; } override auto fun3() { return 1; } } void main() {} Bye, bearophile