Overloaded routines with same arguments pass compilation.
Original Reporter info from Mantis: zoran
-
Reporter name: Zoran Vučenović
Original Reporter info from Mantis: zoran
- Reporter name: Zoran Vučenović
Description:
Function with same name and same parameters, declared in same scope, but only with different result type pass compilation.
If the result type is same, then compiler breaks with Error: overloaded functions have the same parameter list
The two routines with same name same parameter list are identical from the "overloading point of view", regardless of the result type. So, this is a bug, right?
Steps to reproduce:
This should not compile, but it does:
program Project1;
{$mode objfpc}{$H+}
procedure TestOverload(N: Integer);
begin
writeln('Version with no result called');
end;
function TestOverload(N: Integer): Integer;
begin
writeln('Integer version called');
Result := 0;
end;
function TestOverload(N: Integer): String;
begin
writeln('String version called');
Result := '';
end;
begin
TestOverload(0);
end.
Additional information:
Running this program prints "Version with no result called". So it just works with one version.
When I change the order and put the integer version on top, it gets called, so, it seems that the first version declared on top of the others gets executed.
Mantis conversion info:
- Mantis ID: 33604
- Build: 38763
- Version: 3.1.1
- Fixed in version: 3.3.1
- Fixed in revision: 45973 (#b6204580)