The documentation for generics in Delphi mode has a wrong example in section "8.5.2 Record type restrictions"
Original Reporter info from Mantis: Thaddy
-
Reporter name: Thaddy de Koning
Original Reporter info from Mantis: Thaddy
- Reporter name: Thaddy de Koning
Description:
The documentation is written in two modes at the same time, which is confusing since you can not mix objfpc mode syntax with delphi mode syntax.
"In Delphi mode, the record type restrictions will also allow the use of simple types:
Type
generic TList<_T : record> = class(TObject)
public
Type TCompareFunc = function(const Item1, Item2: _T): Integer;
Public
data : _T;
procedure Add(item: _T);
procedure Sort(compare: TCompareFunc);
end;
TIntList = TList<Integer>;"
Additional information:
There are two ways to solve this:
1) use mode delphi for the whole example:
Type
TList<_T : record> = class(TObject)
public
Type TCompareFunc = function(const Item1, Item2: _T): Integer;
Public
data : _T;
procedure Add(item: _T);
procedure Sort(compare: TCompareFunc);
end;
2) Document that the generic type is declared in another unit from the subsequent specialized type and document that a subsequent use in delphi mode changes the expected behavior: a specialized type such as this example in mode Delphi accepts simple types even if the declaration in mode objfpc will prevent that and even if the type limitation to a record type is in a unit written in objfpc mode.
- or both (maybe lengthy...)
Mantis conversion info:
- Mantis ID: 33890
- OS: all
- OS Build: all
- Platform: all
- Version: 3.0.4
- Fixed in version: 3.1.1
- Fixed in revision: 1488 (#c115c8cc)
- Target version: 3.2.0