Operator overloading with generic records: the compiler doesn't properly handle local specializations
Original Reporter info from Mantis: mazolawins
-
Reporter name: Mazolla Winstrol
Original Reporter info from Mantis: mazolawins
- Reporter name: Mazolla Winstrol
Description:
The compiler doesn't handle operator overloading properly when using generic record with local specializations. The code bellow can't be compiled.
=== CODE ===
unit operatorsample;
{$mode delphi}
interface
type
{ TMyRecord }
TMyRecord<T> = record
class operator Add(A,B: TMyRecord<T>): TMyRecord<T>;
end;
implementation
{ TMyRecord }
class operator TMyRecord<T>.Add(A, B: TMyRecord<T>): TMyRecord<T>;
begin
// add implementation
end;
procedure TestIfCompiles;
type
TInteger = TMyRecord<Integer>;
var
N1, N2, N3: TInteger;
begin
N1 := N2 + N3;
end;
end.
=== END ===
To compile this code, i need to move the declarion of the type TInteger to the
global scope, as follows:
=== CODE ===
unit operatorsample;
{$mode delphi}
interface
type
{ TMyRecord }
TMyRecord<T> = record
class operator Add(A,B: TMyRecord<T>): TMyRecord<T>;
end;
TInteger = TMyRecord<Integer>;
implementation
{ TMyRecord }
class operator TMyRecord<T>.Add(A, B: TMyRecord<T>): TMyRecord<T>;
begin
// add implementation
end;
procedure TestIfCompiles;
var
N1, N2, N3: TInteger;
begin
N1 := N2 + N3;
end;
end.
=== END ===
Mantis conversion info:
- Mantis ID: 29792
- OS: All
- OS Build: All
- Platform: All
- Version: 3.0.0
- Fixed in version: 3.1.1
- Fixed in revision: 33211 (#e58488dc)