[fpc-devel] generics defy scoping rules -- Intended?
Sven Barth
pascaldragon at googlemail.com
Tue Nov 25 18:51:57 CET 2025
Martin Frb via fpc-devel <fpc-devel at lists.freepascal.org> schrieb am Di.,
25. Nov. 2025, 17:29:
> On 25/11/2025 16:14, Hairy Pixels via fpc-devel wrote:
>
> On Nov 25, 2025 at 9:55:46 PM, Martin Frb via fpc-devel <
> fpc-devel at lists.freepascal.org> wrote:
>
>> Thanks, which just for confirmation brings up a follow up question. (I
>> haven't used generic function much yet, so maybe I miss something)
>>
>> function Foo (aParam: Integer): integer;
>> generic function Foo<T>(aParam: t) : integer;
>>
>>
>>
>
> yes those are two different functions. The generic function is just a
> template which includes the parsed tokens and is named with $X where X is
> the number of generic parameters. Only at the time of specialization is the
> code generated, until the it's just an array of tokens.
>
> there is a {$modeswitch implicitfunctionspecialization} mode switch ( my
> work so I apologize for the bugs 😂) which infers the parameter type so
> that foo('abc') becomes foo<String>('String').
>
>
> So then with that switch, what will
> foo(1)
>
> resolve to?
>
> - Always the non generic
> - Always the generic
> - Which every is first in scope
> ?
>
The non-generic is preferred as it might provide a better concrete
implementation.
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20251125/14e6f692/attachment.htm>
More information about the fpc-devel
mailing list