Operator overload not working in generics with type restriction
Original Reporter info from Mantis: africanwilddog
-
Reporter name: African Wild Dog
Original Reporter info from Mantis: africanwilddog
- Reporter name: African Wild Dog
Description:
When i try to compile a code with a assignment operator overload on a generic class with type restriction i get this error from compiler: "Impossible to overload assignment for equal types". However, if i remove the type restriction, the code compiles.
Steps to reproduce:
Try to compile the code below:
==== CODE ===
program generic_with_type_restriction ;
{$MODE objfpc}
{$MODESWITCH AdvancedRecords}
type
generic Weak<T: IInterface> = record
private
FValue: T;
public
class operator := (const value: T): specialize Weak<T>; inline;
end;
class operator Weak.:=(const value: T): specialize Weak<T>;
begin
Result.FValue := Value;
end;
begin
end.
============
Additional information:
Just remove the type restriction. Code will compile successfully.
==== CODE ===
program generic_without_type_restriction;
{$MODE objfpc}
{$MODESWITCH AdvancedRecords}
type
generic Weak<T> = record
private
FValue: T;
public
class operator := (const value: T): specialize Weak<T>; inline;
end;
class operator Weak.:=(const value: T): specialize Weak<T>;
begin
Result.FValue := Value;
end;
begin
end.
============
Mantis conversion info:
- Mantis ID: 34030
- Version: 3.0.4