[fpc-pascal] generic proc inference

Sven Barth pascaldragon at googlemail.com
Mon Oct 7 07:54:51 CEST 2019


Ryan Joseph <genericptr at gmail.com> schrieb am Mo., 7. Okt. 2019, 00:16:

>
> >
> >>> 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;
>
> This is debatable I think but I understand why "Ambiguous call to DoThis”
> would make sense. I’m pretty sure C# does this also.
>
> What is the rule then? I’ll have to think about that some more.
>

There is nothing debatable here. If a generic parameter is not used in the
parameter list (cause it's used in the result type (either directly or to
specialize something else), only the body of the routine or even not at
all), then that routine must not be used for implicit specialization.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20191007/ed4d164d/attachment.html>


More information about the fpc-pascal mailing list