View Issue Details

IDProjectCategoryView StatusLast Update
0037111FPCCompilerpublic2021-04-30 09:22
ReporterNoName Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Product Version3.3.1 
Summary0037111: Syntax error for valid generic TList<TPair<String, String>>.Create expression
DescriptionThe expression TList<TPair<String, String>>.Create gives following wrong error:

y.pas(12,26) Fatal: Syntax error, ";" expected but "," found
Steps To Reproduceprogram x;

{$mode Delphi}

uses
  Generics.Collections;

var
  x: TList<TPair<String, String>>;

begin
  x := TList<TPair<String, String>>.Create;
  try
    x.Add(TPair<String, String>.Create('hi', 'bye'));
  finally
    x.Free;
  end;
end.
Additional InformationFree Pascal Compiler version 3.2.0-beta-r20:45235M [2020/05/04] for x86_64
Tagsgenerics
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Relationships

duplicate of 0030503 acknowledgedSven Barth Problem compiling a code using TArray<TArray<Double>> 

Activities

dmz73

2021-04-29 03:22

reporter   ~0130650

I have found that FPC can compile nested generics bracket are used around the inner generic expression.
Unfortunately that kind of expression will not compile in Delphi.
I am hoping this makes it possible to fix this issue quickly and it can be backported to FPC 3.2.x

Example:
program Project1;
{$mode delphi}
type
  TG1<T> = record
    class function f1: T; static;
  end;
  TG2<T> = record
    class function f2: T; static;
  end;

class function TG1<T>.f1: T; begin result := default(T); end;
class function TG2<T>.f2: T; begin result := default(T); end;

begin
  writeln('res1:', (TG1<(TG2<integer>)>.f1).f2); // this works in FPC, fails in Delphi
  writeln('res2:', (TG1<TG2<integer>>.f1).f2); // this fails in FPC, works in Delphi
  readln;
end.

Sven Barth

2021-04-29 09:41

manager   ~0130651

That should definitely not compile in FPC either. O.o Don't rely on that functionality, cause that is something that will be fixed sooner or later.

dmz73

2021-04-30 06:47

reporter   ~0130669

I am not using the TG1<(TG2<integer>)> as it does not compile in Delphi but my hope was that this shows:
1) that most of the nested generics functionality is already implemented
2) that fix could be simple if compiler would perform the same operation as when there are brackets around the inner generic (or assume brackets around inner generics are there)

Sven Barth

2021-04-30 09:22

manager   ~0130670

The problem is not that the specialization itself is not possible (cause it works in non-Delphi modes), the problem is the parser. That is because TG1 can potentially be a variable or function or whatever as well and the compiler needs to handle those situations correctly (because Delphi does) and not parse it as a specialization if it shouldn't be a specialization. The parser only has a single token look ahead and it can really only decide if it's a specialization or not if it encounters the first > (end of specialization) or , (another parameter).

Issue History

Date Modified Username Field Change
2020-05-19 00:19 NoName New Issue
2020-05-19 00:20 NoName Tag Attached: generics
2021-04-29 03:22 dmz73 Note Added: 0130650
2021-04-29 09:41 Sven Barth Note Added: 0130651
2021-04-29 11:21 Marco van de Voort Relationship added duplicate of 0030503
2021-04-30 06:47 dmz73 Note Added: 0130669
2021-04-30 09:22 Sven Barth Note Added: 0130670