overloaded resolution - Improve implicit static array to dynamic array conversion

Issue #63 resolved
Josef Kučera created an issue

Hello, I am utilizing overloaded functions and I have discovered a small inconvenience. Imagine this scenario:

type
  TObjectArray = array of TObject;
  VariantArray = array of Variant;

function Func(APar1: TObject; APar2: Variant): Boolean; overload;
function Func(APar1: TObjectArray; APar2: VariantArray): Boolean; overload;

If I try to call the function with a static array of constants or results of other functions I get an error that no matching overload was found. This is correct, because in this case the array of constants is compiled as a static array of integers and not variants.

function GetValue1(): Integer;
begin
  Result:= 2; // some calculation
end;

begin
  Func([LObject1, LObject2], [GetValue1(), 0]);  // << this does not compile
end.

I propose to enhance the overload resolution of static to dynamic array with automatic conversion of static array of integer (or any other basic type) to a dynamic array of variant.

If I try to call a non overloaded method this conversion is done automatically.

Comments (4)

  1. Josef Kučera reporter

    Hello, I have revisited this suggestion and tried to resolve it. Here is the proposed change to allow the overload resolution to properly select a function/method that accepts "Variant" param (or "array of Variant" param). As regular method calls already worked, this is all that is needed.

    Best regards, Joe

  2. Eric Grange repo owner

    Hi, I added a unit test with what I think was your usage case, but that only required half of your patch.

    Could you provide an updated or extra unit test that could illustrate the case the other half of your patch applies to ? Thanks!

  3. Josef Kučera reporter

    Hi, Yeah, I have double checked the patch and you are correct! The second part is not needed at all. I have initially tried the other change for the simple Variant resolution, but that has already worked.

    Thanks!

  4. Log in to comment