[fpc-devel] Operator overload error when using type restrictions
African Wild Dog
paintedlycaon at gmail.com
Wed Jul 25 01:11:50 CEST 2018
Hello,
Please confirm if this is a bug or my mistake.
When i try to overload a assignment operator on a generic class with type
restriction i get this error: "Impossible to overload assignment for equal
types". However, if i remove the type restriction, the compiles.
==== CODE (compiles) ===
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.
============
==== CODE (doesn't compiles) ===
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.
============
Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180724/fe09e804/attachment.html>
More information about the fpc-devel
mailing list