Ryan Joseph <generic...@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

>
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to