The compiler considers each parameter type "array of Integer" as a different type, and so incompatible, although that seems unintuitive to newcomers.
No. If you have a literal
array of Integer parameter then it will be assignment compatible to other
array of Integer parameters (these are
open array parameters). However if you have a dynamic array in the mix (this can only be the case if you have a named type aka
TIntegerArray = array of Integer as array parameter
or you have a dynamic array variable - like the
arr in
quake004's
Main procedure), then you can pass such a dynamic array to an open array parameter, but not an open array to a dynamic array parameter. (Also if you have multiple different dynamic array types of the same element type, they'll be assignment compatible as well)
What is the problem in
quake004's code is the initialization of the dynamic array variable in
Main:
procedure Main;
var
arr: Array of Integer;
begin
arr := [1, 2, 3];
pass(arr);
end;
FPC 3.0.4 does not yet support dynamic array constructors (or more precisely: it only supports the
Create one for named dynamic arrays), thus the compiler parses the right side of the assignment as a set, resulting in the compiler trying to assign a set to a dynamic array. Thus the error mentioned in the topic:
Incompatible types: got "Set Of Byte" expected "{Dynamic} Array Of LongInt".
The only change necessary is how
Handoko changed the initialization of
arr in
Main:
procedure Main;
var
arr: array of Integer;
begin
SetLength(arr, 3);
arr[0] := 1;
arr[1] := 2;
arr[2] := 3;
pass(arr);
end;