Sign in Join

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

Mailing lists / fpc-pascal / 2016-03

Fpc Bug: Type specialization with Generics and Operator Overloading in Diferent Units

2 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 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

Reply by email

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

Yes that's a bug, maybe even the same as the other one. Please report nevertheless, but please test the examples you post, as nowhere "NullableInteger" is declared (I know what you meant, but when hunting bugs I don't want to hunt bugs in the example code as well).

Regards,
Sven

Reply by email