Discussion:
Problem with generic parameter
(too old to reply)
Gennady Agranov
2016-12-31 06:07:07 UTC
Permalink
Raw Message
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
Дмитрий Померанцев
2016-12-31 09:32:47 UTC
Permalink
Raw Message
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Sven Barth
2016-12-31 18:25:08 UTC
Permalink
Raw Message
Post by Dmitriy Pomerantsev
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
Gennady Agranov
2017-01-01 20:22:56 UTC
Permalink
Raw Message
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
Post by Sven Barth
Post by Dmitriy Pomerantsev
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
_______________________________________________
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Thorsten Engler
2017-01-02 04:28:54 UTC
Permalink
Raw Message
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



From: fpc-devel-***@lists.freepascal.org [mailto:fpc-devel-***@lists.freepascal.org] On Behalf Of Gennady Agranov
Sent: Monday, 2 January 2017 06:23
To: fpc-***@lists.freepascal.org
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
Post by Dmitriy Pomerantsev
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 - fpc-***@lists.freepascal.org <mailto:fpc-***@lists.freepascal.org>
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Sven Barth
2017-01-02 13:30:20 UTC
Permalink
Raw Message
Post by Thorsten Engler
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)).
Post by Thorsten Engler
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

Sven Barth
2017-01-02 13:27:08 UTC
Permalink
Raw Message
Post by Gennady Agranov
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
Post by Gennady Agranov
{$else}
if
Arrays.BinarySearch<TTreeNode>(changes.m_children,node,j,getComparatorByName)
then
Post by Gennady Agranov
{$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
Dmitriy Pomerantsev
2016-12-31 09:38:50 UTC
Permalink
Raw Message
Welcome to five years old bug. :)
http://bugs.freepascal.org/view.php?id=20503

Dmitriy Pomerantsev.
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?
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Loading...