Recent

Author Topic: Problem compiling a generic  (Read 3808 times)

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 363
Problem compiling a generic
« on: May 23, 2018, 01:06:29 am »
uses
   Generics.Collections, Generics.Defaults,;  // library from https://github.com/dathox/generics.collections

//   TEnumerable<T> = class abstract from  Generics.Collections
 
type

  TFslPair<T : TFslObject> = record
   // stuff
  end;

  TFslMap<T : TFslObject> = class(TEnumerable<TFslPair<T>>)       
  private

trying to compile this:

FHIR.Support.Generics.pas(212,55) Fatal: Syntax error, "," expected but "<" found

but it looks like it should work to me - and it does work in delphi, and the equivalent would work in Java... Is this a freepascal issue?

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 363
Re: Problem compiling a generic
« Reply #1 on: May 23, 2018, 01:07:20 am »
btw, this is from https://github.com/grahamegrieve/fhirserver, which I would like to get compiling for FPC

Leledumbo

  • Hero Member
  • *****
  • Posts: 8744
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Problem compiling a generic
« Reply #2 on: May 23, 2018, 06:13:20 am »
  • Did you compile in Delphi mode?
  • What FPC version?

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 363
Re: Problem compiling a generic
« Reply #3 on: May 23, 2018, 09:23:28 am »
yes: {$IFDEF FPC}{$mode delphi}{$ENDIF}.

FPC version 3.0.4

         

Thaddy

  • Hero Member
  • *****
  • Posts: 14158
  • Probably until I exterminate Putin.
Re: Problem compiling a generic
« Reply #4 on: May 23, 2018, 09:30:33 am »
I think you should use trunk, although I am not quite sure it would compile now. The construct is allowed in trunk. Maybe Sven (PascalDragon) has an opinion? He implements most of it.
I just had a look at that code and on sight it should compile. FPC is not able to handle anonymous methods yet, but your code seems not to rely on that. Note I did a visual review, not a compile review. Trunk can handle more delphi compatible generics syntax than 3.0.4 can.
« Last Edit: May 23, 2018, 09:33:59 am by Thaddy »
Specialize a type, not a var.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: Problem compiling a generic
« Reply #5 on: May 23, 2018, 09:42:46 am »
Afaik this is a known problem, and indeed solved in trunk but not the release branch; >> is incorrectly tokenized a as shift.

Quiser

  • Newbie
  • Posts: 2
  • Love Forever
Re: Problem compiling a generic
« Reply #6 on: May 23, 2018, 11:47:25 am »
I have the same problem!

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 363
Re: Problem compiling a generic
« Reply #7 on: May 23, 2018, 07:58:43 pm »
Thanks all. Since trunk is only available as source, it's a heavy lift to get it compiling etc, but I'll give it a go. What might a timeline for a release look like?

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 363
Re: Problem compiling a generic
« Reply #8 on: May 23, 2018, 07:59:46 pm »
">> is incorrectly tokenized a as shift" - breaking the >> with a space doesn't help (in release version)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: Problem compiling a generic
« Reply #9 on: May 24, 2018, 03:14:01 pm »
Thanks all. Since trunk is only available as source, it's a heavy lift to get it compiling etc, but I'll give it a go. What might a timeline for a release look like?

I think timescales of even a full year from now would be too optimistic. Major releases take at least 9-12 months after branching, and  creating the next major branch hasn't been made (or even discussed) yet.

ASerge

  • Hero Member
  • *****
  • Posts: 2212
Re: Problem compiling a generic
« Reply #10 on: May 24, 2018, 09:20:04 pm »
It may be better to use mode OBJFPC?
This is compiled (in trunc, where Generics.Collections exists):
Code: Pascal  [Select][+][-]
  1. {$MODE OBJFPC}
  2. program Project1;
  3.  
  4. uses Generics.Collections;
  5.  
  6. type
  7.   TFslObject = class(TObject)
  8.   end;
  9.  
  10.   generic TFslPair<T: TFslObject> = record
  11.   end;
  12.  
  13.   generic TFslMap<T: TFslObject> = class(specialize TEnumerable<specialize TFslPair<T>>)
  14.   end;
  15.  
  16. begin
  17. end.

Thaddy

  • Hero Member
  • *****
  • Posts: 14158
  • Probably until I exterminate Putin.
Re: Problem compiling a generic
« Reply #11 on: May 24, 2018, 09:29:22 pm »
Well, this also compiles - in trunk! - and is a more sane syntax:
Code: Pascal  [Select][+][-]
  1. {$MODE delphi}
  2. program Project1;
  3.  
  4. uses Generics.Collections;
  5.  
  6. type
  7.   TFslObject = class(TObject)
  8.   end;
  9.  
  10.   TFslPair<T: TFslObject> = record
  11.   end;
  12.  
  13.   TFslMap<T: TFslObject> = class(TEnumerable<TFslPair<T>>)
  14.   end;
  15.  
  16. begin
  17. end.

The issue is trunk vs 3.0.4 and before...... That was a pretty useless contribution. I know you can do better, much better.
« Last Edit: May 24, 2018, 09:32:45 pm by Thaddy »
Specialize a type, not a var.

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 363
Re: Problem compiling a generic
« Reply #12 on: May 24, 2018, 10:27:18 pm »
umm, no, this doesn't compile for me? (at least, not in Lazarus) - is there some magic setting somewhere?

« Last Edit: May 24, 2018, 10:32:41 pm by Grahame Grieve »

 

TinyPortal © 2005-2018