[fpc-pascal] Fpc Bug 3.0: Generics and Operator Overloading
Mazola Winstrol
mazofeifer at gmail.com
Sun Mar 6 19:42:40 CET 2016
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160306/85428b89/attachment.html>
More information about the fpc-pascal
mailing list