[fpc-pascal] generic proc inference
Mattias Gaertner
nc-gaertnma at netcologne.de
Mon Oct 7 16:36:31 CEST 2019
On Mon, 7 Oct 2019 09:38:45 -0400
Ryan Joseph <genericptr at gmail.com> wrote:
>[...]
> > This means you don't support:
> > generic procedure Run<S,T>(a: T; b:S); overload;
>
> That’s correct, this breaks the logic entirely. This to me looks like
> a sneaky way to trick the compiler and since it’s trying to infer
> something from the programmer it doesn’t make sense. If you have a
> better algorithm please post.
I don't know the inner workings of FPC, but for pas2js I will probably
do something like this:
1. If proc has n templates, start with an array of n elements (all nil).
2. for each passed parameter expression do
2.1 Find the argument declaration of this parameter
2.2 resolve the parameter type
2.2 Traverse recursively the parameter and argument type
2.2.1 If the argument types is a template, assign the parameter type. If
the template has already a type then try to find a shared type.
3. Check if all templates have types
>[...]
Mattias
More information about the fpc-pascal
mailing list