Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2016-12

Problem with generic parameter

8 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Gennady Agranov

Hi,

Delphi mode, fpc 3.0.0

I have a Sort method:

type
   TArray<T> = class
     class procedure Sort(var Values: array of T; const Comparer:
IComparer<T>);
   end;

If I call Sort with some real type it compiles and works:

TArray<T>.Sort(string,comparer);

but if i call it from another generic type - it does not compile:

class procedure Arrays<T>.sort(var arr: array of T; const Comparer:
IComparer<T>);
begin
TArray<T>.Sort(arr,comparer);
end;

Fatal: Syntax error, "CREATE" expected but "SORT" found

Anything I can do to make it compile?

Should I try objfp mode?

Thanks,

Gennady

Reply by email

Dmitriy Pomerantsev
to Gennady Agranov: Delphi mode, fpc 3.0.0 I have a Sort method: type TArray<T> = class class procedure…

Welcome to five years old bug. :)
http://bugs.freepascal.org/view.php?id=20503

Dmitriy Pomerantsev.

31.12.2016, 09:08, "Gennady Agranov" :

Show quoted text 8 lines
but if i call it from another generic type - it does not compile: class procedure Arrays<T>.sort(var arr: array of T; const Comparer: IComparer<T>); Fatal: Syntax error, "CREATE" expected but "SORT" found Anything I can do to make it compile?

Reply by email

Gennady Agranov
to Sven Barth

Hi Sven,

Based on bug#20503 you are in charge of support for "generics"? Thanks a lot for your work!

What about this incompatibility - is it a known issue?

         {$ifdef FPC}
         if

Arrays<TTreeNode>.BinarySearch(changes.m_children,node,j,getComparatorByName) then

         {$else}
         if

Arrays.BinarySearch<TTreeNode>(changes.m_children,node,j,getComparatorByName) then

         {$endif}

Thanks,
Gennady

Sven Barth wrote 18 lines
Am 31.12.2016 10:33 schrieb "Дмитрий Померанцев" < >: > > Welcome to five years old bug. :) > http://bugs.freepascal.org/view.php?id=20503 Nope, that's not the same problem. Also the code example of the thread starter did not contain a generic method. Regards, Sven _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Thorsten Engler
to Gennady Agranov

Hi,

Independent of what Delphi may support or not (and I agree that at a minimum in $mode Delphi fpc should not require that IFDEF)…

in a modern compiler I would expect the generic type parameter to be optional in this specific scenario and the compiler infer it from the type of the parameters.

Cheers,

Thorsten

Earlier message 40 lines
From: On Behalf Of Gennady Agranov Sent: Monday, 2 January 2017 06:23 To: Subject: Re: [fpc-devel] Problem with generic parameter Hi Sven, Based on bug#20503 you are in charge of support for "generics"? Thanks a lot for your work! What about this incompatibility - is it a known issue? {$ifdef FPC} if Arrays<TTreeNode>.BinarySearch(changes.m_children,node,j,getComparatorByName) then {$else} if Arrays.BinarySearch<TTreeNode>(changes.m_children,node,j,getComparatorByName) then {$endif} Thanks, Gennady On 12/31/2016 1:25 PM, Sven Barth wrote: Am 31.12.2016 10:33 schrieb "Дмитрий Померанцев" < >: > > Welcome to five years old bug. :) > http://bugs.freepascal.org/view.php?id=20503 Nope, that's not the same problem. Also the code example of the thread starter did not contain a generic method. Regards, Sven

Reply by email

Sven Barth
to Gennady Agranov: Based on bug#20503 you are in charge of support for "generics"? Thanks a lot for your…
"Gennady Agranov" wrote 10 lines
Hi Sven, Based on bug#20503 you are in charge of support for "generics"? Thanks a lot for your work! What about this incompatibility - is it a known issue? {$ifdef FPC} if

Arrays<TTreeNode>.BinarySearch(changes.m_children,node,j,getComparatorByName) then

{$else} if

Arrays.BinarySearch<TTreeNode>(changes.m_children,node,j,getComparatorByName) then

{$endif}

Sounds like generic methods, so you could try with trunk. And it wasn't an incompatibility per se, but a feature we hadn't implemented.

Regards,
Sven

Reply by email

Sven Barth
"Thorsten Engler" wrote 6 lines
Hi, Independent of what Delphi may support or not (and I agree that at a

minimum in $mode Delphi fpc should not require that IFDEF)…

Delphi's generics are hard to parse and FPC's generics simply missed some functionality (and still do in some cases) independently of the mode (e.g. generic methods simply did not exist (they do now in 3.1.1) or one still can't declare generics inside other generics (one of the next things I plan to tackle)).

in a modern compiler I would expect the generic type parameter to be

optional in this specific scenario and the compiler infer it from the type of the parameters.

As long as Delphi doesn't implement type inference I won't touch that topic with a ten meter pole and even then it would not be high priority on my list.

Regards,
Sven

Reply by email