[fpc-pascal] generic proc inference

Mattias Gaertner nc-gaertnma at netcologne.de
Mon Oct 7 14:51:02 CEST 2019


On Mon, 7 Oct 2019 14:37:16 +0200 (CEST)
Michael Van Canneyt <michael at freepascal.org> wrote:

> On Mon, 7 Oct 2019, Mattias Gaertner via fpc-pascal wrote:
> 
>[...]
> I think sven means if you have e.g. 3 functions:
> 
> generic function DoThis<T>(a: T): T; overload;
> begin end;
> 
> generic function DoThis<T,U>(a: T): U; overload;
> begin end;
> 
> function DoThis(aInt : Integer) : Integer;
> 
> begin
> end;
> 
> 
> Should the compiler choose the 3rd non-generic function, or still
> give an error ?

You mean, if a bad overload can be nullified by a good one? That would
be insane...

Yes, Delphi eats it without warning.

And it works even with a generic param:

generic function Run<T,U>(a: T; b: U): T; overload;
begin end;
generic function Run<T>(a: T; b: word): T; overload;
begin end;

Run(3,word(4));

Mattias


More information about the fpc-pascal mailing list