function overloading can be done by differentiating return type only
Original Reporter info from Mantis: leledumbo_cool@yahoo.co.id @leledumbo
-
Reporter name: Mario Ray Mahardhika
Original Reporter info from Mantis: leledumbo_cool@yahoo.co.id @leledumbo
- Reporter name: Mario Ray Mahardhika
Description:
A function can be overloaded only by differentiating the return type. Futhermore, when the function is called, the compiler behaves as if only one of the function is defined.
Steps to reproduce:
The following code demonstrates the behavior (see comments in main block for info):
function f(s: string): string;
begin
f := '''' + s + '''';
end;
function f(s: string): integer;
begin
Val(s,f);
end;
var
i: Integer;
begin
i := f('123'); // Error: Incompatible types: got "ShortString" expected "SmallInt"
WriteLn(f('123')); // Calls function f(s: string): string;
end.
Additional information:
This behavior is found by my friend, he said in Delphi the code compiles and works. However, he didn't give enough details (what Delphi version, how's the behavior when the function is called, etc.). I will add more after he answers.
FPC 2.6.2 is known to have this behavior, too.
Mantis conversion info:
- Mantis ID: 24434
- Build: 24422
- Version: 2.7.1
- Fixed in version: 3.3.1
- Monitored by: » luri (Luri Darmawan), » Hixie (Ian Hickson)