Hello,

Fpc version: 3.0 (the one included with Lazarus 1.6).

Please confirm if it is a bug: it seems the compiler doesn't handle
operator overloading properly when using generic record with local
specializations.


===== Code =====

unit Test;

{$mode delphi}

type
  TMyRecord<T> = record
    class operator Add(A,B: TMyRecord<T>): TMyRecord<T>;
  end;

implementation

class operator TMyRecord<T>.Add(A,B: TMyRecord<T>): TMyRecord<T>;
begin
// add implementation
end;


procedure TestIfCompiles;
type
  TInteger = TMyRecord<Integer>;
var
  N1, N2: TInteger;
begin
  N1 := N2 + N2;  /// DOES NOT COMPILE: Operator is not overloaded:
TMyRecord + TMyRecord
end;

==== END =====



To compile this code, move the declarion of the type TInteger to the global
scope, as follows:



===== Code =====

unit Test;

{$mode delphi}

type
  TMyRecord<T> = record
    class operator Add(A,B: TMyRecord<T>): TMyRecord<T>;
  end;

   TInteger = TMyRecord<Integer>;


implementation

class operator TMyRecord<T>.Add(A,B: TMyRecord<T>): TMyRecord<T>;
begin
// add implementation
end;


procedure TestIfCompiles;
var
  N1, N2: TInteger;
begin
  N1 := N2 + N2;
end;

==== END =====


Regards
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to