[fpc-devel] generic forward declaration?
Michael Van Canneyt
michael at freepascal.org
Tue Jul 29 09:36:41 CEST 2025
On Tue, 29 Jul 2025, Martin Frb via fpc-devel wrote:
> Are there? Or is there something else?
>
> The below compiles. No duplicate TBar. Looks like a forward declaration...
>
> program Project1;{$Mode objfpc}
> type
> generic TBar<A,B> = class; // forward
>
> generic TBar<A, B> = class
> F:A;
> X:B;
> end;
>
> begin
> end.
>
>
>
> But the next does not compile "Identifier not found TBar" (inside TFoo).
> Yet the identifier is clearly there.
>
> https://gitlab.com/freepascal.org/fpc/source/-/issues/24097 seems to say
> it is supported since 2022?
>
> program Project1;
> {$Mode objfpc}
> type
>
> generic TBar<A,B> = class; // forward
>
> generic TFoo<A, B> = class
> F:specialize TBar<A>;
You're missing a type parameter here.
According to the definition, TBar needs 2 type parameters.
> X:B;
> end;
>
> generic TBar<A, B> = class
> F:specialize TFoo<A>;
Same here, you're missing a type parameter. TFoo needs 2 type parameters.
if you fix that (I added B in both cases, just to test) it compiles.
Michael.
More information about the fpc-devel
mailing list