Bug 4855 – When a class has private override member function, the function requires no return value type
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-09-12T07:09:00Z
Last change time
2012-01-29T21:53:57Z
Keywords
accepts-invalid, rejects-valid, spec
Assigned to
nobody
Creator
rayerd.wiz
Comments
Comment #0 by rayerd.wiz — 2010-09-12T07:09:36Z
import std.stdio;
class Base
{
int f() {return 0;}
}
class Derived : Base
{
private override /+int+/ f() {return 1;} // accepts-invalid
}
void main()
{
}
Comment #1 by bearophile_hugs — 2010-09-12T07:59:36Z
I agree this looks a bit strange, and it may even lead to a few bugs, but here DMD is acting as designed, so it's not a true bug.
When you use enum, override and few other things, DMD performs type inference, so the explicit return type is not necessary.
So I presume this bug may be closed.
(If you think this D characteristic is leads to many bugs then this bug report may be kept open, despite the probability of seeing it fixed is low.)
Comment #2 by rayerd.wiz — 2010-09-12T09:55:48Z
Thank you for your reply.
If this characteristic is a design of DMD, I will close this bug report.
What do you think that both look like asymmetry?
import std.stdio;
class Base
{
int f() {return 0;}
int g() {return 0;}
}
class Derived : Base
{
private override /+int+/ f() {return 1;} // accepts
public override /+int+/ g() {return 1;} // rejects
}
void main() {}
main.d(10): Error: function main.Derived.g of type () overrides but is not covariant with main.Base.g of type int()
main.d(10): Error: function main.Derived.g does not override any function
Comment #3 by bearophile_hugs — 2010-09-12T11:14:20Z
I don't know what's going on, but I suggest to keep this bug report open.
Comment #4 by clugdbug — 2010-09-12T19:05:39Z
I think this is a duplicate of bug 3581.
Comment #5 by yebblies — 2012-01-29T21:53:57Z
*** This issue has been marked as a duplicate of issue 3581 ***