Today I discovered a compiler bug (QC#108577).
The following program fails to compile:
program Project1;
{$APPTYPE CONSOLE}
procedure P(M: TArray<TArray<Integer>>);
begin
SetLength(M, 1, 2);
end;
begin
end.
The compiler gags on the SetLength
line and says:
[dcc32 Error] E2029 ')' expected but ',' found
I know I could fix it like this:
procedure P(M: TArray<TArray<Integer>>);
var
i: Integer;
begin
SetLength(M, 1);
for i := low(M) to high(M) do
SetLength(M[i], 2);
end;
but naturally I'm keen to avoid having to resort to this.
The following variant compiles and seems to work:
procedure P(M: TArray<TArray<Integer>>);
type
TArrayOfArrayOfInteger = array of array of Integer;
begin
SetLength(TArrayOfArrayOfInteger(M), 1, 2);
end;
I don't know enough about the implementation details of dynamic arrays, TArray<T>
casting, reference counting etc. to be confident that this is safe.
Is there anybody out there who does know enough to say one way or another whether or not this will produce the correct code at runtime?