<div dir="auto"><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Mattias Gaertner <<a href="mailto:nc-gaertnma@netcologne.de">nc-gaertnma@netcologne.de</a>> schrieb am Mo., 7. Okt. 2019, 11:59:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, 7 Oct 2019 07:54:51 +0200<br>
Sven Barth via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank" rel="noreferrer">fpc-pascal@lists.freepascal.org</a>> wrote:<br>
<br>
> Ryan Joseph <<a href="mailto:genericptr@gmail.com" target="_blank" rel="noreferrer">genericptr@gmail.com</a>> schrieb am Mo., 7. Okt. 2019,<br>
> 00:16:<br>
>[...] <br>
> > >>> 3.<br>
> > >>> timpfuncspez2.pp<br>
> > >>> DoThis<T><br>
> > >>> DoThis<T,U><br>
> > >>> Delphi gives an error "Ambiguous call to DoThis". FPC silently<br>
> > >>> selects the one with only one param. IMO this is dangerous, it<br>
> > >>> should give an error. <br>
> > ><br>
> > > generic function DoThis<T>(a: T): T; overload;<br>
> > > begin end;<br>
> > > generic function DoThis<T,U>(a: T): U; overload;<br>
> > > begin end;<br>
> > ><br>
> > > begin<br>
> > > DoThis(3); // both fits, should give an error<br>
> > > end; <br>
> ><br>
> > This is debatable I think but I understand why "Ambiguous call to<br>
> > DoThis” would make sense. I’m pretty sure C# does this also.<br>
> ><br>
> > What is the rule then? I’ll have to think about that some more.<br>
> > <br>
> <br>
> There is nothing debatable here. If a generic parameter is not used<br>
> in the parameter list (cause it's used in the result type (either<br>
> directly or to specialize something else), only the body of the<br>
> routine or even not at all), then that routine must not be used for<br>
> implicit specialization.<br>
<br>
Yes, but does that mean to tell the programmer, that he is using these<br>
overloads the wrong way (as Delphi does), or should the compiler silently skip invalid overloads.<br>
For the sake of don't-point-the-gun-at-my-foot, I would vote for the<br>
first.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">I'm also for an error. </div><div dir="auto"><br></div><div dir="auto">However does Delphi pick a suitable non-generic overload if one exists aside from the two generic ones? </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>