Passing Static Array in parameter issue
Original Reporter info from Mantis: warleyalex
-
Reporter name: warleyalex
Original Reporter info from Mantis: warleyalex
- Reporter name: warleyalex
Description:
----------------------------------------------------
type
TJyArray = array [0..15] of byte;
Procedure Init(const X : TJyArray);
var
I: byte;
begin
for I := Low(X) to High(X) do
WriteLn('Integer at index ', I, ' is ', X[I]);
end;
var
JyArray : TJyArray;
begin
JyArray[8] := 8;
JyArray[7] := 7;
JyArray[6] := 6;
JyArray[5] := 5;
Init(JyArray);
(*
Integer at index 0 is 0
Integer at index 1 is 0
Integer at index 2 is 0
Integer at index 3 is 0
Integer at index 4 is 0
Integer at index 5 is 5
Integer at index 6 is 6
Integer at index 7 is 7
Integer at index 8 is 8
Integer at index 9 is 0
Integer at index 10 is 0
Integer at index 11 is 0
Integer at index 12 is 0
Integer at index 13 is 0
Integer at index 14 is 0
Integer at index 15 is 0
*)
---------------------------
This is working as expected!
----------------------------------------------------
Steps to reproduce:
I think we have a minor issue, when passing static arrays in parameter the following situation:
---------------------------------
type
TFixedSizeArray = array [0..9] of Integer;
TDynamicArray = array of Integer;
procedure SomeProc(fixed : TFixedSizeArray; dynamico : TDynamicArray);
begin
fixed[0] := fixed[0] + 1;
SetLength(dynamico, 20);
dynamico[0] := fixed[0] + dynamico[0];
end;
var f : TFixedSizeArray;
d : TDynamicArray;
begin
f[0] := 100;
SetLength(d, 10);
d[0] := 50;
SomeProc(f, d);
WriteLn(IntToStr( f[0]) );
// pas2js returns 101 ---> the expected value would be 100
WriteLn(IntToStr( d[0]) ); //151 --> correct
---------------------------------
Note that f[0] should be unchanged after call SomeProc method!
f is a TFixedSizeArray.
Additional information:
pas2js emitt: -----------> mod.SomeProc(
mod.f,$mod.d);
I think the correct is: --> mod.SomeProc(
mod.f.slice(0),$mod.d);
Mantis conversion info:
- Mantis ID: 33194
- Build: 0.9.5
- Fixed in version: 1.0.0
- Monitored by: » @JohnML1 (John Landmesser)
- Target version: 1.0.0