View Issue Details

IDProjectCategoryView StatusLast Update
0022402FPCCompilerpublic2020-07-24 09:55
ReporterTunahan ÜNAL Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status confirmedResolutionopen 
Platformx86OSWindows 
Product Version2.6.0 
Summary0022402: Generic forward type declaration
DescriptionGenerics implementation have problem when Delphi mode is on with following code sapmle.
I'm trying to define generic and enumerable list which is compatible with delphi syntax.



ubase.pas(31,45) Error: Specialization is only supported for generic types
Steps To Reproduceunit uBase;

{$IFDEF FPC}
  {$MODE Delphi}
{$ENDIF}

type

  TTestEnumerator<T> = class;

  TTestList<T> = class
    function GetEnumerator : TTestEnumerator<T>; //<<<<< Fails
  end;

  TTestEnumerator<T> = class
  private
    FTestList: TTestList<T>;
  end;


implementation

function TTestList<T>.GetEnumerator: TBaseListEnumerator<T>;
begin
  Result := TTestEnumerator<T>.Create(Self);
end;
Tagsgenerics
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Relationships

related to 0034128 acknowledged Support for forward declarations of generic types 

Activities

2012-07-09 15:28

 

ubase.pas (421 bytes)

Sven Barth

2012-07-10 09:49

manager   ~0060933

Please test with 2.7.1 and report back as Delphi compatibility of generics was improved a lot there.

Regards,
Sven

Bi0T1N

2020-04-05 02:05

reporter   ~0121912

Last edited: 2020-04-05 02:06

View 2 revisions

Compiling above code gives:
  uBase.pas(7,5) Fatal: Syntax error, "INTERFACE" expected but "TYPE" found

Changing the code to
unit uBase;

{$IFDEF FPC}
  {$MODE Delphi}
{$ENDIF}

interface

type

  TTestEnumerator<T> = class;

  TTestList<T> = class
    function GetEnumerator : TTestEnumerator<T>; //<<<<< Fails
  end;

  TTestEnumerator<T> = class
  private
    FTestList: TTestList<T>;
  end;


implementation

function TTestList<T>.GetEnumerator: TBaseListEnumerator<T>;
begin
  Result := TTestEnumerator<T>.Create(Self);
end; 

gives
  uBase.pas(14,48) Fatal: Internal error 2012101001
in 3.2.0rc1 and 3.3.1-r44326

Marco van de Voort

2020-04-05 13:41

manager   ~0121939

It tested the code with Delphi XE3, and modified it lightly till it compiled. And indeed FPC IE's on it.
genericsforwardbug.pp (490 bytes)   
// gives IE 2012101001, while compiles in Delphi
{$ifdef fpc}
{$mode delphi}
{$else}
{$apptype console}
{$endif}

uses
  SysUtils;

type
  TTestEnumerator<T> = class;

  TTestList<T> = class
    function GetEnumerator : TTestEnumerator<T>; //<<<<< Fails
  end;

  TTestEnumerator<T> = class
  private
    FTestList: TTestList<T>;
  end;



function TTestList<T>.GetEnumerator: TTestEnumerator<T>;
begin
  Result := TTestEnumerator<T>.Create;
end;

begin
end.
genericsforwardbug.pp (490 bytes)   

Sven Barth

2020-07-24 09:55

manager   ~0124297

Updated the title to better reflect the problem

Issue History

Date Modified Username Field Change
2012-07-09 15:26 Tunahan ÜNAL New Issue
2012-07-09 15:28 Tunahan ÜNAL File Added: ubase.pas
2012-07-10 09:49 Sven Barth Note Added: 0060933
2012-07-10 09:49 Sven Barth Status new => feedback
2020-04-05 02:05 Bi0T1N Note Added: 0121912
2020-04-05 02:06 Bi0T1N Note Edited: 0121912 View Revisions
2020-04-05 13:30 Bi0T1N Tag Attached: generics
2020-04-05 13:41 Marco van de Voort File Added: genericsforwardbug.pp
2020-04-05 13:41 Marco van de Voort Note Added: 0121939
2020-04-05 13:41 Marco van de Voort Assigned To => Marco van de Voort
2020-04-05 13:41 Marco van de Voort Status feedback => confirmed
2020-04-05 13:41 Marco van de Voort FPCTarget => -
2020-05-06 15:13 Sven Barth Relationship added related to 0034128
2020-07-22 15:47 Marco van de Voort Assigned To Marco van de Voort =>
2020-07-24 09:55 Sven Barth Summary Generics => Generic forward type declaration
2020-07-24 09:55 Sven Barth Note Added: 0124297