[fpc-devel] generics with type-identifier "object" - documented yes, but ...?
Martin Frb
lazarus at mfriebe.de
Fri Mar 4 18:31:36 CET 2022
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?
More information about the fpc-devel
mailing list