Discussion:
Operator overload error when using type restrictions
Add Reply
African Wild Dog
2018-07-24 23:11:50 UTC
Reply
Permalink
Raw Message
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
Sven Barth via fpc-devel
2018-07-25 05:41:11 UTC
Reply
Permalink
Raw Message
Post by African Wild Dog
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.
With what compiler version did you test? Cause with trunk your example
works here...

Regards,
Sven
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/
African Wild Dog
2018-07-25 12:37:52 UTC
Reply
Permalink
Raw Message
Em quarta-feira, 25 de julho de 2018, Sven Barth via fpc-devel <
Post by Sven Barth via fpc-devel
With what compiler version did you test? Cause with trunk your example
works here...
I have tested with 3.0.4 version.

Regards

Loading...