View Issue Details

IDProjectCategoryView StatusLast Update
0034037FPCCompilerpublic2020-11-15 16:30
ReporterVojtech Cihak Assigned ToFlorian  
Status closedResolutionfixed 
Product Version3.1.1 
Fixed in Version3.3.1 
Summary0034037: Generics - nil has to be treated as T(nil)
Descriptionnil 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 Reproduceprogram project1;
{$mode objfpc}{$H+}

  Classes, FGL;

  TBaseClass = class (TObject)

  generic TFPGObjectListEx<T: TBaseClass> = class (specialize TFPGObjectList<T>)
    function GetItemByID(AID: Integer): T;

{$R *.res}

function TFPGObjectListEx.GetItemByID(AID: Integer): T;
  Result:=nil; //T(nil);

TagsNo tags attached.
Fixed in Revision39934
Attached Files


has duplicate 0038070 resolvedFlorian Delphi mode generic class with class constraint isn't allowed to be nilled. 


Thaddy de Koning

2018-07-26 13:37

reporter   ~0109688

Last edited: 2018-07-26 13:40

View 3 revisions

This has a relationship somewhere (this looks familiar to me, I commented on this a a solution?) Can't find it yet, though.


2018-10-07 09:01

reporter   ~0111294

Here it was said about the similar that the compiler is flawed and should remain so: “by design”

Thaddy de Koning

2018-10-07 10:48

reporter   ~0111297

Yes. So this can be closed for the same reason?


2018-10-07 11:30

administrator   ~0111298

No, it must be compilable.

Thaddy de Koning

2018-10-07 12:04

reporter   ~0111299

Last edited: 2018-10-07 12:11

View 3 revisions

Florian, that was the whole thing why I re-opened....the linked report...
If T has a class specifier like "class, constructor" or that T needs to be or inherited from a class, T is known to be a class and therefor determinable as nil, which is completely valid for a class.

That was my whole point. Am I wrong (as so often) to assume that my first suggestion was right (in the other report..)

The code (without cast) still not compiles in either mode delphi(with appropiate syntax changes) or mode objfpc.

Vojtech Cihak

2018-10-14 19:09

reporter   ~0111401

Works. Thanks.

Issue History

Date Modified Username Field Change
2018-07-26 10:47 Vojtech Cihak New Issue
2018-07-26 13:37 Thaddy de Koning Note Added: 0109688
2018-07-26 13:38 Thaddy de Koning Note Edited: 0109688 View Revisions
2018-07-26 13:40 Thaddy de Koning Note Edited: 0109688 View Revisions
2018-10-07 09:01 VaalKIA Note Added: 0111294
2018-10-07 10:48 Thaddy de Koning Note Added: 0111297
2018-10-07 11:30 Florian Note Added: 0111298
2018-10-07 11:30 Florian Status new => acknowledged
2018-10-07 12:04 Thaddy de Koning Note Added: 0111299
2018-10-07 12:09 Thaddy de Koning Note Edited: 0111299 View Revisions
2018-10-07 12:11 Thaddy de Koning Note Edited: 0111299 View Revisions
2018-10-14 07:38 Florian Fixed in Revision => 39934
2018-10-14 07:38 Florian Status acknowledged => resolved
2018-10-14 07:38 Florian Fixed in Version => 3.3.1
2018-10-14 07:38 Florian Resolution open => fixed
2018-10-14 07:38 Florian Assigned To => Florian
2018-10-14 19:09 Vojtech Cihak Note Added: 0111401
2018-10-14 19:09 Vojtech Cihak Status resolved => closed
2020-11-15 16:30 Sven Barth Relationship added has duplicate 0038070