[fpc-devel] generics defy scoping rules -- Intended?
Sven Barth
pascaldragon at googlemail.com
Tue Nov 25 14:19:04 CET 2025
Martin Frb via fpc-devel <fpc-devel at lists.freepascal.org> schrieb am Mo.,
24. Nov. 2025, 21:30:
> Normally, if I refer to a type then the first type found by the name
> will be taken => and if that type is not compatible, then I get an error.
> => See Example 2
>
> But, if I try to specialize a generic, and some other type by the same
> name exists, and comes first in the search order, then it will be ignored.
>
> The specialize below, ignores the "TFoo = class" which can not be used,
> and finds the TFoo from unit1.
>
> Is that intended?
>
Yes, because in fact they don't have the same name. The name of a generic
with a single parameter is essentially "TFoo<>" while that of a generic
with two parameters is "TFoo<,>".
The amount of generic parameters is part of the type or routine name.
Note: non-Delphi modes currently don't allow type overloading in the same
unit, but it's on my ToDo-list to make it possible there as well, but it
requires some adjustments to allow compatibility to existing code which is
why it's not possible yet.
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20251125/225ad296/attachment.htm>
More information about the fpc-devel
mailing list