Sign in Join

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

Mailing lists / fpc-devel / 2018-06

RandomFrom vs Generics

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Gabor Boros

Hi All,

This

var
   x:Integer;
   a:array of Integer;
begin
   x:=RandomFrom(a);

code works with 3.0.4 but cannot compile with trunk and got "Error: Generics without specialization cannot be used as a type for a variable". Tried x:=specialize RandomFrom<Integer>(a); but got "Error: Identifier not found "RandomFrom"". How to call RandomFrom with trunk?

Gabor

Reply by email

Sven Barth
to Gabor Boros

Gabor Boros schrieb am Mi., 6. Juni 2018, 08:09:

Show quoted text 16 lines
Hi All, This var x:Integer; a:array of Integer; begin x:=RandomFrom(a); code works with 3.0.4 but cannot compile with trunk and got "Error: Generics without specialization cannot be used as a type for a variable". Tried x:=specialize RandomFrom<Integer>(a); but got "Error: Identifier not found "RandomFrom"". How to call RandomFrom with trunk?

Seems like a bug due to there being multiple overloads plus the generic. Would you please report that to the bug tracker?
Does it work if you add "overload;" to the generic's declaration in the Math unit?

Regards,
Sven

Reply by email

Gabor Boros
to Sven Barth

2018. 06. 06. 9:05 keltezéssel, Sven Barth via fpc-devel írta:

Seems like a bug due to there being multiple overloads plus the generic. Would you please report that to the bug tracker?

Done:

https://bugs.freepascal.org/view.php?id=33829

Does it work if you add "overload;" to the generic's declaration in the Math unit?

No. (After modified the math.pp and build the whole compiler from scratch with make all zipinstall.)

Gabor

Reply by email

Sven Barth
to Gabor Boros

Gabor Boros schrieb am Mi., 6. Juni 2018, 10:15:

Show quoted text 8 lines
2018. 06. 06. 9:05 keltezéssel, Sven Barth via fpc-devel írta: > Seems like a bug due to there being multiple overloads plus the generic. > Would you please report that to the bug tracker? Done: https://bugs.freepascal.org/view.php?id=33829

Thanks!

Show quoted text 7 lines
> Does it work if you add "overload;" to the generic's declaration in the > Math unit? No. (After modified the math.pp and build the whole compiler from scratch with make all zipinstall.)

It was worth a try. 🤷‍♀️ Thank you for testing.

Regards,
Sven

Reply by email