Sign in Join

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

Mailing lists / fpc-devel / 2018-07

Operator overload error when using type restrictions

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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.

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

Reply by email

Sven Barth
to African Wild Dog
African Wild Dog wrote 6 lines
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

Reply by email

African Wild Dog
to Sven Barth

Em quarta-feira, 25 de julho de 2018, Sven Barth via fpc-devel <

escreveu: With what compiler version did you test? Cause with trunk your example

works here...

I have tested with 3.0.4 version.

Regards

Reply by email