[fpc-devel] Implicit function specialization precedence
Ryan Joseph
genericptr at gmail.com
Tue Apr 6 22:47:37 CEST 2021
> On Apr 6, 2021, at 12:57 PM, Sven Barth <pascaldragon at googlemail.com> wrote:
>
> In this specific case the two functions also are *not* ambigous, because for the non-generic Test the parameter requires an implicit conversion, but the implicit specialization does not. For example if there would be a "Test(aArg: LongInt)" instead of the generic the compiler would pick that instead of the string one. So if you move the check for generic vs. non-generic to the end of is_better_candidate all the other rules to determine this will take precedence.
So the root of the problem is that we have no way to choose the generic function via explicit casting? That makes sense and presumably I can use the final result of is_better_candidate to determine this? In your example:
Writeln(Test('Hello World')); // is_better_candidate res = -1
Writeln(Test(42)); // is_better_candidate res = 1
Writeln(Test(String(42))); // is_better_candidate res = -1
I'm struggling to see how the operator influenced the result. Res is -1 in both cases so how do we know which Test we want to call?
Regards,
Ryan Joseph
More information about the fpc-devel
mailing list