Recent

Author Topic: Generic TObjectList sorting in 3.2.2 vs. 3.2.4  (Read 1079 times)

hukka

  • Jr. Member
  • **
  • Posts: 57
    • Github
Generic TObjectList sorting in 3.2.2 vs. 3.2.4
« on: March 01, 2026, 02:43:14 am »
Earlier today I updated my setup to the latest Lazarus release and FPC 3.2.4 branch, and spent a few hours trying to figure out why the sprites in my game were no longer getting sorted properly. The list I was sorting is a generic TObjectList<TSprite>.
Anyway, it turns out that I had to change the definition of the sorting method as follows:

function CompareSprites(constref A, B: TSprite): Integer;
- This worked in FPC 3.2.2
- This doesn't actually end up sorting the list in FPC 3.2.4 but doesn't cause an error

function CompareSprites(A, B: TSprite): Integer;
- This just freezes in FPC 3.2.2
- This works in FPC 3.2.4

FWIW, using "const" instead of "constref" also freezes in 3.2.2.

I realize 3.2.4 is not even near to a release yet, but have I stumbled upon a bug? Or was the bug in 3.2.2 instead? Or am I just being dense?
« Last Edit: March 01, 2026, 02:48:32 am by hukka »

Thaddy

  • Hero Member
  • *****
  • Posts: 18764
  • To Europe: simply sell USA bonds: dollar collapses
Re: Generic TObjectList sorting in 3.2.2 vs. 3.2.4
« Reply #1 on: March 01, 2026, 09:58:01 am »
3.2.2/4 need constref. This is dropped in main/trunk, where it has changed to const. This change is only applicable to rtl-generics (generics.collections).
So it is not a bug. You should use constref in 3.2.2/4 and const in trunk/main.

It is also documented:
https://wiki.freepascal.org/User_Changes_Trunk#Generics.Collections_&_Generics.Defaults
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

hukka

  • Jr. Member
  • **
  • Posts: 57
    • Github
Re: Generic TObjectList sorting in 3.2.2 vs. 3.2.4
« Reply #2 on: March 01, 2026, 08:20:44 pm »
So it is not a bug. You should use constref in 3.2.2/4 and const in trunk/main.

Thanks! I had missed that in the documentation.

PascalDragon

  • Hero Member
  • *****
  • Posts: 6349
  • Compiler Developer
Re: Generic TObjectList sorting in 3.2.2 vs. 3.2.4
« Reply #3 on: March 02, 2026, 09:48:26 pm »
3.2.2/4 need constref. This is dropped in main/trunk, where it has changed to const. This change is only applicable to rtl-generics (generics.collections).
So it is not a bug. You should use constref in 3.2.2/4 and const in trunk/main.

It is also documented:
https://wiki.freepascal.org/User_Changes_Trunk#Generics.Collections_&_Generics.Defaults

Please note that 3.2.4 also requires const instead of constref. Due to 3.2.4 not being released yet the wiki for 3.2.4 changes has not been updated yet.

Thaddy

  • Hero Member
  • *****
  • Posts: 18764
  • To Europe: simply sell USA bonds: dollar collapses
Re: Generic TObjectList sorting in 3.2.2 vs. 3.2.4
« Reply #4 on: March 03, 2026, 10:31:24 am »
Thanks. So it is backported in this case.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

 

TinyPortal © 2005-2018