[fpc-devel] generic forward declaration?

Sven Barth pascaldragon at googlemail.com
Tue Jul 29 23:39:13 CEST 2025


Martin Frb via fpc-devel <fpc-devel at lists.freepascal.org> schrieb am Di.,
29. Juli 2025, 20:57:

> On 29/07/2025 09:36, Michael Van Canneyt wrote:
> > Same here, you're missing a type parameter. TFoo needs 2 type parameters.
>
> Ups, thanks.
>
> Any obvious  (or non obvious) mistake of mine in the below?
>
> Because either of the 2 commented specialize cause errors in the
> generics... (but only if TFoo.F  SWAPS the order of param).
>
> It compiles fine
> - with both the specialize commented
> - or with TBar replacing "F" with the commented "F"
>
>
>
> program Project1;
> {$Mode objfpc}
> type
>
>    generic TBar<A,B> = class; // forward   // LINE 5
>
>    generic TFoo<A, B> = class
>      F:specialize TBar<A,B>;
>      X:B;
>    end;      // LINE 10
>
>    generic TBar<A, B> = class
>      F:specialize TFoo<B,A>;
>      //F:specialize TFoo<A,B>;
>      X:B;
>    end;
>
>    //x1 = specialize TBar<Byte, Boolean>;  // project1.lpr(5,28) Fatal:
> Syntax error, "identifier" expected but ";" found
>    //x2 = specialize TFoo<Byte, Boolean>; // project1.lpr(10,6) Fatal:
> Syntax error, "identifier" expected but ";" found
>
> begin
>
> end.
>

Please report a bug. Though this might end up not compiling nevertheless
due to the specialization chain going ad infinitum...

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20250729/50789de9/attachment.htm>


More information about the fpc-devel mailing list