[fpc-devel] Question about generics / what is checked, and what not -- and why?
Sven Barth
pascaldragon at googlemail.com
Mon Oct 20 08:00:08 CEST 2025
Martin Frb via fpc-devel <fpc-devel at lists.freepascal.org> schrieb am So.,
19. Okt. 2025, 17:50:
> On 19/10/2025 17:33, Hairy Pixels via fpc-devel wrote:
>
> 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.
>
>
>
> Well, yes, it may be unimplemented in the parser... And maybe that is all
> of it.
>
That's precisely it, nothing more, nothing less. These corner cases are
fixed on a case-by-case base, cause the locations where a fix needs to
happen are easier found that way than trying to understand and fix the
whole parser.
So if you want to see this fixed, then please report a bug.
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20251020/16f53f1b/attachment-0001.htm>
More information about the fpc-devel
mailing list