[fpc-pascal] generic proc inference

Mattias Gaertner nc-gaertnma at netcologne.de
Mon Oct 7 11:12:26 CEST 2019


On Sun, 6 Oct 2019 18:16:16 -0400
Ryan Joseph <genericptr at gmail.com> wrote:

>[...]
> >>> 3.
> >>> timpfuncspez2.pp
> >>> DoThis<T>
> >>> DoThis<T,U>
> >>> Delphi gives an error "Ambiguous call to DoThis". FPC silently
> >>> selects the one with only one param. IMO this is dangerous, it
> >>> should give an error.    
> > 
> > generic function DoThis<T>(a: T): T; overload;
> > begin end;
> > generic function DoThis<T,U>(a: T): U; overload;
> > begin end;
> > 
> > begin
> >  DoThis(3); // both fits, should give an error
> > end;  

I gave a bad example. Here is a better one:

generic procedure DoThis<T>(a: T; b:T); overload;
begin end;
generic procedure DoThis<T,U>(a: T; b:U); overload;
begin end;

begin
  DoThis(1,2); 
end;  

fpc selects second, but IMO should give an error .

Mattias


More information about the fpc-pascal mailing list