Mattias Gaertner <nc-gaert...@netcologne.de> schrieb am Mo., 7. Okt. 2019, 11:59:
> On Mon, 7 Oct 2019 07:54:51 +0200 > Sven Barth via fpc-pascal <fpc-pascal@lists.freepascal.org> wrote: > > > 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. > > Yes, but does that mean to tell the programmer, that he is using these > overloads the wrong way (as Delphi does), or should the compiler silently > skip invalid overloads. > For the sake of don't-point-the-gun-at-my-foot, I would vote for the > first. > I'm also for an error. However does Delphi pick a suitable non-generic overload if one exists aside from the two generic ones? Regards, Sven >
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal