[fpc-devel] Implicit function specialization with := operator overload

Hairy Pixels genericptr at gmail.com
Sun Feb 5 03:29:03 CET 2023


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



More information about the fpc-devel mailing list