Sign in Join

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

Mailing lists / fpc-pascal / 2016-03

Fpc Bug 3.0: Generics and Operator Overloading

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Mazola Winstrol

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

Reply by email

Sven Barth
to Mazola Winstrol
"Mazola Winstrol" wrote 6 lines
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.

Yes, that's a bug. Please report.

Regards,
Sven

Reply by email