Sign in Join

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

Mailing lists / fpc-devel / 2023-02

Implicit function specialization with := operator overload

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

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

Hairy Pixels

I’ve somewhat forgotten the order things happen when resolving overloads but is it even possible to make this example work with implicit function specialization?

Right now it fails and I suspect that’s because the operator overload is not considered in the correct order (or at all) but is this problem even solvable or tractable given how the compiler works currently? If you manually specialize it works but that I would expect since the correct function body is known and this the operator overload can be selected for the parameter type.

===========================

{$mode objfpc}
{$modeswitch advancedrecords}
{$modeswitch implicitfunctionspecialization}
program test;
type
  generic TPtr<T> = record
    private type PT = ^T;
    private
      pointer: PT;
    public
      class operator :=(right: PT): TPtr;
  end;
class operator TPtr.:=(right: PT): TPtr;
begin
  result.pointer := right;
end;
generic procedure DoThis<T>(p: specialize TPtr<T>);
begin
end;
var
  value: Integer;
begin
  DoThis(@value);
end.

Regards,
Ryan Joseph

Reply by email