[fpc-devel] generic forward declaration?

Martin Frb lazarus at mfriebe.de
Tue Jul 29 20:57:27 CEST 2025


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.


More information about the fpc-devel mailing list