[fpc-devel] Implicit function specialization precedence

Sven Barth pascaldragon at googlemail.com
Sat May 8 19:24:08 CEST 2021


Am 06.05.2021 um 17:33 schrieb Ryan Joseph via fpc-devel:
> I found something sneaky I'd like to confirm before I decide what to do about it.
>
> 1) "T" in TAnyClass<T> is specialized as Integer from the first parameter with TSomeClass (which is TAnyClass<Integer>).
> 2) "U" is getting specialized as String by looking at the parameters in Compare() in which "U"(the second generic parameter) is String.
>
> This specializes the procedure correctly but it uses a very sneaky method which is very hard to discern. I feel like that if a generic parameter is already used (like T in specialize TCallback<T, U>) then no further attempt should be made to look at the parameters and in the example below "U" would not be found and the function would fail to implicitly specialize.
There is nothing sneaky if one defines that the parameters are evaluated 
left to right and those that are already found and used later on (like 
T) are simply fixed then thus in the example it uses the already found 
type. But if the picked type wouldn't mach, for example if TCallback<,> 
would be declared as TCallback<T: TObject; U> instead then trying to 
specialize the function would simply fail.

Regards,
Sven


More information about the fpc-devel mailing list