[fpc-pascal] Operator overload resolution with arrays

Martok listbox at martoks-place.de
Mon Feb 5 13:01:15 CET 2018


Hi all,

I'm having some logical problems with fgl generic lists and operator overloads.
This is essentially the same issue as discussed last year on the forum as
<http://forum.lazarus.freepascal.org/index.php?topic=36089.0>.
I know how to work around it, just... it doesn't seem very consistent.

Take the following simple declaration:
--------
type
  TTriangleIndex = array[0..2] of Integer;
  TFacetList = specialize TFPGList<TTriangleIndex>;

  operator = (A, B: TTriangleIndex): boolean;
--------
This will not work:
fgl.pp(948,50) Error: Operator is not overloaded: "TTriangleIndex" =
"TTriangleIndex"

So, for arrays, the overloaded operator is not found, even though it is in the
same interface section.

However, this arcane beast would work (although Codetools bail on the double
specialization):
--------
  TTriangleIndex = array[0..2] of Integer;
  generic TArrayContainer<T> = record
    x: T;
    class operator = (A, B: specialize TArrayContainer<T>): boolean;
    // mimic 'default' attribute on x
    class operator := (A: T): specialize TArrayContainer<T>; inline;
    class operator := (A: specialize TArrayContainer<T>): T; inline;
  end;
  TFacetList = specialize TFPGList<specialize TArrayContainer<TTriangleIndex>>;
--------

Class operators defined on the used type itself are taken into account. That
feels a bit inconsistent, given that their scope is equivalent in any other use?

I know it's been like that forever, but... should it be?

-- 
Regards,
Martok

Ceterum censeo b32079 esse sanandam.




More information about the fpc-pascal mailing list