[fpc-devel] Question about generics / what is checked, and what not -- and why?

Hairy Pixels genericptr at gmail.com
Sun Oct 19 17:33:55 CEST 2025


 On Oct 19, 2025 at 10:27:50 PM, Martin Frb via fpc-devel <
fpc-devel at lists.freepascal.org> wrote:

> Given an non-constrained param, then (in code) any member is assumed to
> be ok.
> But in declarations, members of the param can only be used if the
> compiler knows them.
>
>   generic TGenA<T1,T2> = class
>     X: T1;
>     Y: T2.unknown;
>   end;
>
> What reason may there be to reject the line for Y?
>

I agree the compiler can not know that T2.unknown is a valid member before
specializing so it should be valid syntax.

I think it's just a limitation in the parser. Ideally some subset of
typeless syntax should be allowed during the initial parse and only only
validated once the the type is specialized.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20251019/64970580/attachment.htm>


More information about the fpc-devel mailing list