Sign in Join

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

Mailing lists / fpc-devel / 2022-03

generics with type-identifier "object" - documented yes, but ...?

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

According to  https://www.freepascal.org/docs-html/ref/refse53.html the keyword "object" is allowed as a "type identifier" for identifiers in the "template list" of a generic definition.

Yet, the below does not compile (tested with 3.2.0 / 3.2.2 / 3.2.3 and 3.3.1 from 2022-Feb-10)

program Project1; {$mode objfpc}{$H+}
type
   generic TFoo<X: object> = class   end;
Neither does this work (only tested 3.2.3)
type
   TX = object end;
   generic TFoo<X: TX> = class end;
Whereas each of the below does work fine:
   generic TFoo<X: record> = class   end;
   generic TFoo<X: class> = class   end;
   generic TFoo<X: TObject> = class   end;

The same applies for: "generic TFoo<X: ###> = record end;". So the type of the generic itself seems not to affect this.

--------
Similar, the doc says that the keyword "interface" is allowed, but this does not work:
  generic TFoo<X: interface> = class   end;
However using IInterface (or any declared interface type) does work   generic TFoo<X: IInterface> = class   end;

--------

As a side note, the diagram for "identifier list" on the above doc page, seems to indicate that the "type identifier" after the colon can be a comma separated list.
Is that meant to be like that?

Reply by email