Skip to content

Overloading a generic method with the same name in different units

Summary

If I have two overloaded functions in a unit, FPC detects the the correct one but if I split them in two units, it will raise an error: Error: Wrong number of parameters specified for call to "Test"

System Information

Lazarus 2.3.0 (rev main-2_3-1668-g34b3b9a49a) FPC 3.3.1 x86_64-win64-win32/win64

Example Project

unit Unit1; 
{$mode Delphi}
interface
function Test(const A: Rawbytestring): Integer; overload;
implementation
function Test(const A: Rawbytestring): Integer;
begin
end;
end.
unit Unit2; 
{$mode Delphi} 
interface
function Test<T>(const A: TArray<T>): Integer; overload;
implementation
function Test<T>(const A: TArray<T>): Integer;
begin
end;
end.
program Project1;
 
{$mode Delphi}
 
uses unit1, unit2;
 
var
  S: Rawbytestring;
  I: Integer;
begin
  I := Test(S);
end.    

What is the expected (correct) behavior?

Detect the correct overload.

Related issues: #38083 (closed) and #39680 (closed). Maybe it is related to 90844c20

Edited by Okoba
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information