Delphi 10.1 changed something with regards to overload resolution, causing the following to stop compiling:

Delphi 10.1 changed something with regards to overload resolution, causing the following to stop compiling:

type
  Func = reference to function(const Arg: T): R;

type
  Alg = record
    class procedure Exec(const f: Func); overload; static;
  end;

...

Alg.Exec(integer.ToString);

This compiled in Delphi 10 update 1 but does not compile in Delphi 10.1 update 2, instead failing with "E2250 There is no overloaded version of 'Alg.Exec' that can be called with these arguments".

Thinking this was a regression, I tried to narrow it down a bit further, but found that even in Delphi 10 I cannot get the following to compile:

type
  TRec = record
    x: integer;
  end;

  TRecHelper = record helper for TRec
    function ToString: string; overload;
    class function ToString(const Value: TRec): string; overload; static;
end;

...

  Alg.Exec(TRec.ToString);

This fails with the same message.

If I rename the function TRec.ToString() so that it is not the same as the class function name, then all is fine and it compiles great in either.

So did Embarcadero fix an overload resolution inconsistency, rather than introduce a regression? In my view, the compiler should be able to find that the class function is suitable.

Thoughts?

Comments

Post a Comment