View Issue Details

IDProjectCategoryView StatusLast Update
0031437FPCCompilerpublic2019-08-10 13:41
ReporterChristian HadiAssigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
PlatformWindowsOSWindows 10 64bitOS Version
Product Version3.1.1Product Build35475 
Target VersionFixed in Version 
Summary0031437: Method using generics constraint inside class cause compile error
DescriptionAttached sample code for testing
Additional InformationError messages:
=======================

Free Pascal Compiler version 3.1.1 [2017/02/24] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Win64 for x64
Compiling generics_constraint_inside_class_bug.pp
generics_constraint_inside_class_bug.pp(25,34) Error: function header doesn't match the previous declaration "readSomething2$1:T2;"
generics_constraint_inside_class_bug.pp(11,22) Error: Found declaration: readSomething2$1:T2;
generics_constraint_inside_class_bug.pp(29,34) Error: function header doesn't match any method of this class "readSomething3$1:TGenTest$1<BUG_GENERICS_CONSTRAINT_INSIDE_CLASS.readSomething3$1T3>;"
generics_constraint_inside_class_bug.pp(12,22) Error: Found declaration: readSomething3$1:TGenTest$1<BUG_GENERICS_CONSTRAINT_INSIDE_CLASS.TNormalFuncTest.readSomething3$1T3>;
generics_constraint_inside_class_bug.pp(37,35) Error: function header doesn't match any method of this class "readSomething5$1(var T2);"
generics_constraint_inside_class_bug.pp(17,23) Error: Found declaration: readSomething5$1(var T2);
generics_constraint_inside_class_bug.pp(41,35) Error: function header doesn't match any method of this class "readSomething6$1(var TGenTest$1$crc2ED50C58);"
generics_constraint_inside_class_bug.pp(18,23) Error: Found declaration: readSomething6$1(var TGenTest$1$crcE7D92CDE);
generics_constraint_inside_class_bug.pp(46,4) Fatal: There were 8 errors compiling module, stopping
Fatal: Compilation aborted
Error: D:\fpc\3.1.1\bin\x86_64-win64\ppcx64.exe returned an error exitcode
Tagsgenerics
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files
  • generics_constraint_inside_class_bug.pp (1,220 bytes)
    Program Bug_Generics_Constraint_Inside_Class;
    {$mode objfpc}
    uses classes, sysutils;
    
    type
      generic TGenTest<T: TObject> = class
      end;
      
      TNormalFuncTest = class
        generic function readSomething1<T1>(): T1;
        generic function readSomething2<T2: TObject>(): T2;
        generic function readSomething3<T3: TObject>(): specialize TGenTest<T3>;
      end;
      
      TNormalProcTest = class
        generic procedure readSomething4<T1>(var data: T1);
        generic procedure readSomething5<T2>(var data: T2);
        generic procedure readSomething6<T3: TObject>(var data: specialize TGenTest<T3>);
      end;  
    
    generic function TNormalFuncTest.readSomething1<T1>(): T1;
      begin
      end;  
      
    generic function TNormalFuncTest.readSomething2<T2: TObject>(): T2;
      begin
      end;    
      
    generic function TNormalFuncTest.readSomething3<T3: TObject>(): specialize TGenTest<T3>;
      begin
      end;
      
    generic procedure TNormalProcTest.readSomething4<T1>(var data: T1);
      begin
      end;
      
    generic procedure TNormalProcTest.readSomething5<T2: TObject>(var data: T2);
      begin
      end;
      
    generic procedure TNormalProcTest.readSomething6<T3: TObject>(var data: specialize TGenTest<T3>);  
      begin
      end;
     
    begin 
    end.

Relationships

related to 0035943 new Generics: Error: Class type expected, but got "T" 

Activities

Christian Hadi

2017-02-24 13:25

reporter  

generics_constraint_inside_class_bug.pp (1,220 bytes)
Program Bug_Generics_Constraint_Inside_Class;
{$mode objfpc}
uses classes, sysutils;

type
  generic TGenTest<T: TObject> = class
  end;
  
  TNormalFuncTest = class
    generic function readSomething1<T1>(): T1;
    generic function readSomething2<T2: TObject>(): T2;
    generic function readSomething3<T3: TObject>(): specialize TGenTest<T3>;
  end;
  
  TNormalProcTest = class
    generic procedure readSomething4<T1>(var data: T1);
    generic procedure readSomething5<T2>(var data: T2);
    generic procedure readSomething6<T3: TObject>(var data: specialize TGenTest<T3>);
  end;  

generic function TNormalFuncTest.readSomething1<T1>(): T1;
  begin
  end;  
  
generic function TNormalFuncTest.readSomething2<T2: TObject>(): T2;
  begin
  end;    
  
generic function TNormalFuncTest.readSomething3<T3: TObject>(): specialize TGenTest<T3>;
  begin
  end;
  
generic procedure TNormalProcTest.readSomething4<T1>(var data: T1);
  begin
  end;
  
generic procedure TNormalProcTest.readSomething5<T2: TObject>(var data: T2);
  begin
  end;
  
generic procedure TNormalProcTest.readSomething6<T3: TObject>(var data: specialize TGenTest<T3>);  
  begin
  end;
 
begin 
end.

Sven Barth

2017-03-03 17:35

manager   ~0098601

First of constraints may only be declared inside the declaration, not the definition, so remove them there.
That said readSomething3<>() and readSomething6<>() still fail though due to the parameter/result using T3 which is supposed to be an TObject for TGenTest<>... *sigh*

Issue History

Date Modified Username Field Change
2017-02-24 13:25 Christian Hadi New Issue
2017-02-24 13:25 Christian Hadi File Added: generics_constraint_inside_class_bug.pp
2017-02-24 13:26 Christian Hadi Tag Attached: generics
2017-03-03 17:32 Sven Barth Assigned To => Sven Barth
2017-03-03 17:32 Sven Barth Status new => assigned
2017-03-03 17:35 Sven Barth Note Added: 0098601
2017-03-03 17:35 Sven Barth Assigned To Sven Barth =>
2017-03-03 17:35 Sven Barth Assigned To => Sven Barth
2017-03-03 17:35 Sven Barth Status assigned => new
2017-03-03 22:50 Sven Barth Assigned To Sven Barth =>
2019-08-10 13:41 Sven Barth Relationship added related to 0035943