May 17, 2009 [Issue 2999] New: Return-type overloading should be error | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=2999 Summary: Return-type overloading should be error Product: D Version: 2.030 Platform: PC OS/Version: All Status: NEW Keywords: accepts-invalid Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: rsinfu@gmail.com This code compiles without error: -------------------- short foo() { return 1; } int foo() { return 2; } -------------------- Yes, the above example is not so serious because if you try to use foo, the compiler will spit an error. But it will be serious when function overriding is involved: -------------------- interface I { short foo(); } interface J { int foo(); } class C : I, J { override short foo() { return 1; } override int foo() { return 2; } } void main() { I i = new C; J j = new C; writeln(i.foo); writeln(j.foo); } -------------------- The compiler silently accepts this code. And the result is: -------------------- 1 10289153 -------------------- Note that the lower 16-bit of 10289153 is 1. Thus, the short foo() is invoked. If the declaration order of C.foo is reversed, the result becomes -------------------- 2 2 -------------------- In this case, int foo() is invoked. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 22, 2012 [Issue 2999] Return-type overloading should be error | ||||
---|---|---|---|---|
| ||||
Posted in reply to rsinfu@gmail.com | http://d.puremagic.com/issues/show_bug.cgi?id=2999 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |andrej.mitrovich@gmail.com Resolution| |FIXED --- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-01-21 18:03:49 PST --- The compiler doesn't accept this code anymore in 2.057, marking as fixed. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation