Sign in Join

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

Mailing lists / fpc-devel / 2025-11

Strange error / Why / generic in wrapper class

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Martin Frb
The first 2 procedures show that
      var   v2:  TWrap1.specialize TTest4<TObject>;

is valid. The generic can be specialized directly for the variable.

But, if that variable is anywhere within TWrap1, then it fails. Why?

program p1;{$Mode objfpc}
type
   TFoo = class
     procedure       Foo2;
   end;
   generic TGen<T2: TObject> = class
     procedure       Foo2;
   end;

  TWrap1 = class
  public type
    generic TTest4<T2: TObject> = class
      procedure       Foo2;
    end;

   public
     procedure         P1;
   end;
var
   gTest4:  TWrap1.specialize TTest4<TObject>;

{ TFoo }

procedure TFoo.Foo2;
var
   v2:  TWrap1.specialize TTest4<TObject>;
begin
end;
procedure TGen.Foo2;
var
   v2:  TWrap1.specialize TTest4<TObject>;
begin
end;
// TWRAP1
procedure TWrap1.TTest4.Foo2;
var     // V2: project1.lpr(50,32) Error: Parameters or result types
cannot contain local type definitions. Use a separate type definition in
a type block.
   v2:  TWrap1.specialize TTest4<TObject>;
begin
end;
procedure TWrap1.P1;
var        // V2: project1.lpr(50,32) Error: Parameters or result types
cannot contain local type definitions. Use a separate type definition in
a type block.
   v2:  TWrap1.specialize TTest4<TObject>;
begin
end;
begin
end.

Reply by email

Sven Barth
to Martin Frb

Martin Frb via fpc-devel schrieb am Fr.,
28. Nov. 2025, 14:52:

Show quoted text 69 lines
The first 2 procedures show that var v2: TWrap1.specialize TTest4<TObject>; is valid. The generic can be specialized directly for the variable. But, if that variable is anywhere within TWrap1, then it fails. Why? program p1;{$Mode objfpc} type TFoo = class procedure Foo2; end; generic TGen<T2: TObject> = class procedure Foo2; end; TWrap1 = class public type generic TTest4<T2: TObject> = class procedure Foo2; end; public procedure P1; end; var gTest4: TWrap1.specialize TTest4<TObject>; { TFoo } procedure TFoo.Foo2; var v2: TWrap1.specialize TTest4<TObject>; begin end; procedure TGen.Foo2; var v2: TWrap1.specialize TTest4<TObject>; begin end; // TWRAP1 procedure TWrap1.TTest4.Foo2; var // V2: project1.lpr(50,32) Error: Parameters or result types cannot contain local type definitions. Use a separate type definition in a type block. v2: TWrap1.specialize TTest4<TObject>; begin end; procedure TWrap1.P1; var // V2: project1.lpr(50,32) Error: Parameters or result types cannot contain local type definitions. Use a separate type definition in a type block. v2: TWrap1.specialize TTest4<TObject>; begin end; begin end.

Bug, please report.

Regards,
Sven

Reply by email