Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2025-11

Issue with const constraint in Delphi mode specialize (Fun with Delphi mode)

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Frb

It appears the below code can distinguish between the 2 TFoo (generic vs constant).

But if the constraint to the generic is an "const integer" then how to you specialize it?
The 2 commented lines give errors.
   project1.lpr(16,14) Error: Identifier not found "TBar"

Originally I had a "var TBar: integer" too, but then it was
    project1.lpr(16,16) Error: Illegal expression
program Project1; {$Mode delphi}
type
   TBar<const A: integer> = class   end;
   TFoo<A> = class   end;
var
   TFoo: integer;
   x: pointer;
begin
   x := Pointer( TFoo<1> false );  // (TFoo < 1) > False
   x := Pointer( TFoo<byte> .Create );
   //x := TBar<1> .Create ;
   //x := Pointer( TBar<1> .Create );
end.

    ================================
Also got issues with

program Project1; {$Mode delphi}
uses Unit1;
type    TFoo<A> = class   end;
var
   TFoo: integer;
   x: pointer;
begin
   x := Pointer( TFoo<1> false );  // variable TFoo
   x := Pointer( TFoo< TObject);  // variable TFoo
//but trying to continue the bool exression with another compare
   x := Pointer( TFoo< TObject > False); // ERROR
end.
unit Unit1; {$mode ObjFPC}{$H+} interface
    type   TClass = class of TObject;
    operator <(a: integer; b: TClass): boolean;
implementation
operator<(a: integer; b: TClass): boolean;  begin result:=true;  end;
end.

Reply by email