[fpc-devel] Impossible CONST generic constraints in forward declarations...?
Martin Frb
lazarus at mfriebe.de
Tue Nov 25 20:41:21 CET 2025
According to
https://forum.lazarus.freepascal.org/index.php/topic,52157.msg383991.html#msg383991
1) Contstraint given in the interface declaration MUST be dropped in the
implementation
(though it does not explicitly mention methods in a class in the
interface or implementation)
2) Constraints in a "forward" declaration in the implementation (or a
program?) must be kept.
But I cannot figure out how to do it for "const" constraints
For FooProc3 neither keeping, nor dropping works. Both give errors.
program Project1; {$mode ObjFPC}
type
generic TGeneric1<G1Param> = class end;
TFoo = class
generic procedure FooProc1<T1: specialize TGeneric1<byte>; T2:
TObject>(a: T1);
generic procedure FooProc2<T1; T2: TObject>(a: T1);
generic procedure FooProc3<T1; const T2: integer>(a: T1);
end;
generic procedure TFoo.FooProc1<T1; T2>(a: T1); begin {} end;
generic procedure TFoo.FooProc2<T1; T2>(a: T1); begin {} end;
//generic procedure TFoo.FooProc3<T1; T2>(a: T1); begin {} end; //
project1.lpr(16,24) Error: Function header doesn't match any method of
this class "FooProc3$2(T1);"
generic procedure TFoo.FooProc3<T1; const T2: integer>(a: T1); begin {}
end; // project1.lpr(17,43) Error: Generic constraint not allowed here
begin
end.
Also, forward seems to have lost all checking.
It compiles, even if the forward has a different constraint.
program Project1;
{$mode ObjFPC}
type
TX1 = class end;
TX2 = class end;
generic procedure Proc4<T1; T2: TX1>(a: T1); forward;
generic procedure Proc4<T1; T2:TX2>(a: T1); begin {} end;
begin
end.
More information about the fpc-devel
mailing list