[fpc-pascal] Operator not overloaded

Thomas Kurz fpc.2021 at t-net.ruhr
Thu Jun 23 19:45:02 CEST 2022


Hello,

I have tried to create an example as minimalistic as possible. I have three files:

*** file: pathfinding.pas ***

unit PathFinding;

{$mode objfpc}

interface

type generic TAStar<T> = class (TObject)
  public function FindPath (const AStart: T; const ADestination: T): Boolean; virtual;
end;

implementation

function TAStar.FindPath (const AStart: T; const ADestination: T): Boolean;
  var current: T;
  begin
    current:=Default(T);
    if (current = ADestination) then Exit (false);
  end;

end.

*** file: testtypes.pas ***

unit testTypes;

{$mode objfpc}

interface

type TTileSegment = record
  A: NativeUInt;
  B: NativeUInt;
end;

operator = (ALeft: TTileSegment; ARight: TTileSegment): Boolean;
operator < (ALeft: TTileSegment; ARight: TTileSegment): Boolean;
operator > (ALeft: TTileSegment; ARight: TTileSegment): Boolean;

implementation

operator = (ALeft: TTileSegment; ARight: TTileSegment): Boolean;
  begin
    Exit (True);
  end;

operator < (ALeft: TTileSegment; ARight: TTileSegment): Boolean;
  begin
    Exit (True);
  end;

operator > (ALeft: TTileSegment; ARight: TTileSegment): Boolean;
  begin
    Exit (True);
  end;

end.

*** file: project1.lpr ***

program project1;

{$mode objfpc}

uses testtypes, PathFinding;

var x: specialize tastar<ttilesegment>;

begin
  x := specialize tastar<ttilesegment>.create;
end.

************** 

When compiling, I get this error:

pathfinding.pas(17,17) Error: Operator is not overloaded: "TTileSegment" = "TTileSegment"

Which I don't understand -- because the "=" operator is defined in tesstypes.pas.

Am I doing something wrong or is this behavior a bug?

Kind regards,
Thomas



More information about the fpc-pascal mailing list