SRL Archive - Lape

Lape arrays bug


Chris

2014-07-09 08:09:54


procedure startTest();
var
IntArr: TIntegerArray;
begin
// Initialize the Integer Array to have one value at position 0, being 1.
IntArr := [1];

writeln('IntArr:');
writeln(IntArr);

// Set that first value to 5.
IntArr[0] := 5;
end;


var
i: Integer;
begin
// Invoke the procedure three times.
for i := 0 to 2 do
startTest();
end.

Using Lape, this prints:
Compiled successfully in 124 ms.
IntArr:
[1]
IntArr:
[5]
IntArr:
[5]
Successfully executed.

Interpreter set to PascalScript:
Compiled successfully in 16 ms.
IntArr:
[1]
IntArr:
[1]
IntArr:
[1]
Successfully executed.

I've tried this with a TStringArray and array of Int64 too. Same results.

Used Simba version 1004. After asking on the IRC chat about Lape versions because I might've found a bug and would not want to report a bug which has already been fixed, Wizzup said I should try:
http://l0.lt/builders/codecompletion-test/builds/22
http://l0.lt/builders/master/builds/626
So I did. Same results.

slacky

2014-07-09 08:18:48

Definitely a bug worth looking in to, thanks for reporting it.

As far as I see the only (reasonable) workaround is to call SetLength(..) on the array __after__ initialized, with the size.


procedure startTest();
var IntArr: TIntegerArray;
begin
IntArr := [1];
SetLength(IntArr,Length(IntArr));
writeln('IntArr:', IntArr);
IntArr[0] := 5;
end;


var
i: Integer;
begin
for i := 0 to 2 do
startTest();
end.

nielsie95

2014-08-12 07:54:41

Thanks, I'll look into it :)