Generics - nil has to be treated as T(nil)
Original Reporter info from Mantis: Blaazen @Blaazen
-
Reporter name: Vojtech Cihak
Original Reporter info from Mantis: Blaazen @Blaazen
- Reporter name: Vojtech Cihak
Description:
nil has to be treated as T(nil) in constrained generic class (here it is TObject descendant). Compiler stops with "project1.lpr(20,11) Error: Incompatible types: got "Pointer" expected "$gendef2"".
Steps to reproduce:
program project1;
{$mode objfpc}{$H+}
uses
Classes, FGL;
type
TBaseClass = class (TObject)
end;
generic TFPGObjectListEx<T: TBaseClass> = class (specialize TFPGObjectList<T>)
function GetItemByID(AID: Integer): T;
end;
{$R *.res}
function TFPGObjectListEx.GetItemByID(AID: Integer): T;
begin
{...}
Result:=nil; //T(nil);
end;
begin
end.
Mantis conversion info:
- Mantis ID: 34037
- OS: Linux
- OS Build: Chakra 64-bit
- Build: 39507
- Platform: amd64
- Version: 3.1.1
- Fixed in version: 3.3.1
- Fixed in revision: 39934 (#eea088c5)