View Issue Details

IDProjectCategoryView StatusLast Update
0035934FPCCompilerpublic2019-08-09 10:26
ReporterDaniel SapoundjievAssigned ToSven Barth 
PrioritynormalSeverityminorReproducibilityalways
Status acknowledgedResolutionopen 
Product Version3.0.4Product Build 
Target VersionFixed in Version 
Summary0035934: Class variable declaration of nested generic classes type
DescriptionCompilation error - Fatal: Syntax error, "," expected but "<" found
when compiling the following code

unit Unit2;

{$mode delphiunicode}

interface

uses
  Classes, SysUtils;

type

  TFirstClass<T> = class

  end;

  TSecondClass<T> = class

  end;

  TTestClass = class
  public
    testVar: TFirstClass<TSecondClass<TObject>>;
  end;

implementation

end.
Steps To ReproduceCompile the code
Tagsgenerics
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Relationships

related to 0030503 acknowledgedSven Barth Problem compiling a code using TArray<TArray<Double>> 
related to 0024283 new Generics syntax error, ">" expected but "<" found 

Activities

Thaddy de Koning

2019-08-09 10:05

reporter   ~0117602

This code compiles in trunk and 3.2. correct

Sven Barth

2019-08-09 10:11

manager   ~0117604

Nested specializations are currently not supported.

As a workaround you can use this:

=== code begin ===

  TTestClass = class
  public type
    TSecondClassTObject = specialize TSecondClass<TObject>;
  public
    testVar: TFirstClass<TSecondClassTObject>;
  end;

=== code end ===

Thaddy de Koning

2019-08-09 10:18

reporter   ~0117607

That is strange Sven. I just tested that code.

program testit;
uses ee_genmat;
begin
end.

-------------------
unit Unit2;

{$mode delphiunicode}

interface

uses
  Classes, SysUtils;

type

  TFirstClass<T> = class

  end;

  TSecondClass<T> = class

  end;

  TTestClass = class
  public
    testVar: TFirstClass<TSecondClass<TObject>>;
  end;

implementation

end.

Except for some notes, compiles correct.

Output:
fpc -vwhnql -Fu/usr/local/lib/fpc/3.3.1/units/arm-linux/* -Fl/usr/lib/gcc/arm-linux-gnueabihf/6.3.0 "unit2.pas" (in directory: /home/asta)
Hint: (11030) Start of reading config file /etc/fpc.cfg
Hint: (11031) End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 3.3.1-r42590 [2019/08/06] for arm
Copyright (c) 1993-2019 by Florian Klaempfl and others
(1002) Target OS: Linux for ARMHF
(3104) Compiling unit2.pas
2 131/1.024 Kb Used
unit2.pas(12,15) Note: (5071) Private type "TFirstClass$1.T" never used
unit2.pas(16,16) Note: (5071) Private type "TSecondClass$1.T" never used
unit2.pas(18,3) Note: (5071) Private type "TSecondClass$1<SYSTEM.TObject>.T" never used
unit2.pas(14,3) Note: (5071) Private type "TFirstClass$1<UNIT2.TSecondClass$1<SYSTEM.TObject>>.T" never used
(1008) 27 lines compiled, 0.5 sec
(1022) 2 hint(s) issued
(1023) 4 note(s) issued
Compilation finished successfully.

Sven Barth

2019-08-09 10:25

manager   ~0117609

I just checked. The *declaration* will indeed work correctly, but using it in the code (e.g. instantiating testVar inside TTestClass' constructor) will fail:

=== code begin ===

// of course add "constructor Create" to TTestClass as well

constructor TTestClass.Create;
begin
  testVar := TFirstClass<TSecondClass<TObject>>.Create;
end;

=== code end ===

This will result in:

=== output begin ===

Target OS: Win32 for i386
Compiling .\fpctests\tgentest.pp
tgentest.pp(26,48) Error: Illegal expression
tgentest.pp(26,49) Fatal: Syntax error, ";" expected but "identifier CREATE" found
Fatal: Compilation aborted

=== output end ===

And as long as not both, declarations and inline specializations work I won't consider nested specializations as working.

Though I just noticed that in mode ObjFPC this would compile as well (with the code adjusted for mode ObjFPC of course)... I hate parsing of generics, especially the mode Delphi ones...

Issue History

Date Modified Username Field Change
2019-08-06 11:28 Daniel Sapoundjiev New Issue
2019-08-09 10:01 Sven Barth Tag Attached: generics
2019-08-09 10:05 Thaddy de Koning Note Added: 0117602
2019-08-09 10:11 Sven Barth Assigned To => Sven Barth
2019-08-09 10:11 Sven Barth Status new => acknowledged
2019-08-09 10:11 Sven Barth FPCTarget => -
2019-08-09 10:11 Sven Barth Note Added: 0117604
2019-08-09 10:18 Thaddy de Koning Note Added: 0117607
2019-08-09 10:25 Sven Barth Note Added: 0117609
2019-08-09 10:25 Sven Barth Relationship added related to 0030503
2019-08-09 10:26 Sven Barth Relationship added related to 0024283