View Issue Details

IDProjectCategoryView StatusLast Update
0037259FPCCompilerpublic2020-06-27 23:13
Reporterdmz73 Assigned ToSven Barth  
PrioritynormalSeverityminorReproducibilityalways
Status assignedResolutionopen 
Platformx86_64OSWindows 
Product Version3.2.0 
Summary0037259: Compiler reports error "Can't determine which overloaded function to call" when one parameter is generic
DescriptionGeneric record contains overloaded procedure where number of parameters is the same and one parameter in one procedure is generic.
Calling this procedure from within the record results in error "Can't determine which overloaded function to call".
This same code compiles in Delphi.
Steps To ReproduceCompile the following example project:

program Project1;

{$mode delphi}

type
  TRec<T> = record
  public
    procedure SetRec(A1: boolean; A2: string); overload;
    procedure SetRec(A1: boolean; A4: T); overload;
    procedure Test;
  end;

procedure TRec<T>.SetRec(A1: boolean; A2: string);
begin end;

procedure TRec<T>.SetRec(A1: boolean; A4: T);
begin end;

procedure TRec<T>.Test;
begin
  Self.SetRec(true, default(T)); // error is reported here
end;

begin
end.
Additional InformationI have tried to compile the example project in the latest trunk version and it still reports the same error.
Tagsgenerics
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

dmz73

2020-06-27 08:46

reporter   ~0123609

I would like you to reconsider the severity of this issue, I believe this is a major issue and almost a showstopper for anyone using generics in a serious way specially in code that has been created with Delphi.
For FPC alone this issue makes overloaded functions almost impossible to use with generics.
In Delphi they have taken a pragmatic approach and when there is a specific type and generic type version of a function that compiler could choose, the compiler will choose the specific type function. This makes it very easy to write generic code with few special cases. In FPC one has to be very careful not to create conflicting overloads and then create a generic function with lots of IF THEN ELSE IF code just to work around broken compiler.

Issue History

Date Modified Username Field Change
2020-06-26 03:17 dmz73 New Issue
2020-06-26 07:12 Cyrax Tag Attached: generics
2020-06-27 08:46 dmz73 Note Added: 0123609
2020-06-27 23:13 Sven Barth Assigned To => Sven Barth
2020-06-27 23:13 Sven Barth Status new => assigned