View Issue Details

IDProjectCategoryView StatusLast Update
0034037FPCCompilerpublic2018-10-14 21:09
ReporterVojtech CihakAssigned ToFlorian 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformamd64OSLinuxOS VersionChakra 64-bit
Product Version3.1.1Product Build39507 
Target VersionFixed 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+}

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.
TagsNo tags attached.
Fixed in Revision39934
FPCOldBugId
FPCTarget
Attached Files

Activities

Thaddy de Koning

2018-07-26 15:37

reporter   ~0109688

Last edited: 2018-07-26 15: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.

VaalKIA

2018-10-07 11:01

reporter   ~0111294

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

https://bugs.freepascal.org/view.php?id=33961

Thaddy de Koning

2018-10-07 12:48

reporter   ~0111297

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

Florian

2018-10-07 13:30

administrator   ~0111298

No, it must be compilable.

Thaddy de Koning

2018-10-07 14:04

reporter   ~0111299

Last edited: 2018-10-07 14: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 21:09

reporter   ~0111401

Works. Thanks.

Issue History

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