View Issue Details

IDProjectCategoryView StatusLast Update
0035943FPCCompilerpublic2019-08-17 14:15
ReportersilvioprogAssigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Product Version3.3.1Product Build 
Target VersionFixed in Version 
Summary0035943: Generics: Error: Class type expected, but got "T"
DescriptionHi.

Consider the following test:

program Project1;

{$MODE DELPHI}

uses Classes;

type
  TFoo<T: TPersistent> = class(TPersistent)
  end;

  TBar = class(TPersistent)
  public
    function Test<T: TPersistent>: TFoo<T>;
  end;

function TBar.Test<T>: TFoo<T>;
begin
  Result := nil;
end;

begin
end.


On Delphi, it compiles fine, however, on FPC, I've got the following problem:

Compile Project, Target: project1: Exit code 1, Errors: 3
project1.lpr(16,29) Error: Class type expected, but got "T"
project1.lpr(16,15) Error: Function header doesn't match any method of this class "Test$1:<erroneous type>;"
project1.lpr(13,14) Error: Found declaration: Test$1:TFoo$1<PROJECT1.TBar.Test$1T>;


Is this a bug, or some special switch missing in the example?

Thank you!
Tagsgenerics
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Relationships

related to 0031437 new Method using generics constraint inside class cause compile error 

Activities

Thaddy de Koning

2019-08-15 08:29

reporter   ~0117680

Last edited: 2019-08-15 08:33

View 3 revisions

A rewrite compiles;
program Project1;

{$MODE DELPHI}

uses Classes;

type
  TFoo<T: TPersistent> = class(TPersistent)
  end;

  TBar<T:Tpersistent> = class(TPersistent)
  public
    function Test: TFoo<T>;
  end;

function TBar<T>.Test: TFoo<T>;
begin
  Result := nil;
end;
begin
end.


silvioprog

2019-08-16 15:26

reporter   ~0117702

Please don't try to obfuscate my issue with a non sense answer. You are suggesting a class specialization, but the issue refers to a bug in *method specialization*.

Thaddy de Koning

2019-08-17 14:15

reporter   ~0117716

It is not obfuscating it is offering an alternative syntax that works both in Delphi and Freepascal.

Issue History

Date Modified Username Field Change
2019-08-09 17:14 silvioprog New Issue
2019-08-10 13:38 Sven Barth Tag Attached: generics
2019-08-10 13:41 Sven Barth Relationship added related to 0031437
2019-08-15 08:29 Thaddy de Koning Note Added: 0117680
2019-08-15 08:31 Thaddy de Koning Note Edited: 0117680 View Revisions
2019-08-15 08:33 Thaddy de Koning Note Edited: 0117680 View Revisions
2019-08-16 15:26 silvioprog Note Added: 0117702
2019-08-17 14:15 Thaddy de Koning Note Added: 0117716