[fpc-pascal] Fpc Bug: Type specialization with Generics and Operator Overloading in Diferent Units
Mazola Winstrol
mazofeifer at gmail.com
Sun Mar 6 19:54:48 CET 2016
Hello,
Fpc version: 3.0 (the same included with lazarus 1.6).
Please confirm if it is a bug:
If i declare a generic record with overloaded add operation, i need to
specialize the type in the same unit for the compiler recognize the
overloading.
=== Code ===
unit MyRecordDefinition;
{$mode delphi}
interface
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
////
end;
end.
......................
Unit MyRecordSpecialization;
{$mode delphi}
interface
uses
MyRecordDefinition;
type
TInteger = TMyRecord<Integer>;
implementation
procedure TestIfCompiles;
var
N1, N2: NullableInteger;
begin
N1 := N2 + N2; // DOESN'T COMPILE: Operator is not overloaded: TMyRecord
+ TMyRecord
end;
end.
==== END ====
To get this code compiled, i need to move the specialized type TInteger to
the same unit where the generic type TMyRecord is declared.
==== code ===
unit MyRecordDefinition;
{$mode delphi}
interface
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
////
end;
end.
......................
Unit MyRecordSpecialization;
{$mode delphi}
interface
uses
MyRecordDefinition;
implementation
procedure TestIfCompiles;
var
N1, N2: NullableInteger;
begin
N1 := N2 + N2; // DOESN'T COMPILE: Operator is not overloaded: TMyRecord
+ TMyRecord
end;
end.
=== END ====
Best regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160306/579a2b51/attachment.html>
More information about the fpc-pascal
mailing list