← board

Array-constructor statement-arg fails differently when a preceding param has a dynarray field

Symptom

type TBuf = record Bytes: array of Byte; Len: Integer; end;
procedure Check(const name: AnsiString; const buf: TBuf; const a: array of Byte);
begin
  writeln(name, ' ', Length(a));
end;
var b: TBuf;
begin
  Check('hi', b, [1,2,3,4,5]);   { error: too many array constant elements () }
end.

Plain reduced shapes (string+record param, no dynarray field; or string+ simple-var param) call fine as a statement with the inline [...] literal — they instead hit by-reference argument must be a variable (), i.e. they hit the already-known bug. This specific shape — a const record parameter whose type has a dynamic-array field sitting before the open-array parameter — produces a different error message instead. Root cause not isolated beyond this; flagging the distinguishing factor (preceding dynarray-bearing record param) for whoever picks this up.

Isolation attempts (2026-06-30)

Call shape Error
f([4,5]); (procedure, no other params) by-reference argument must be a variable ()
Check('hi', rv, [1,2,3]); where rv: TRec (TRec = record x: Integer end, no dynarray) by-reference argument must be a variable ()
Check('hi', b, [1,2,3,4,5]); where b: TBuf (TBuf has an array of Byte field) too many array constant elements ()

Workaround

Bind the literal to a local typed const array first, then pass the named const instead of the inline [...]:

const expect: array[0..4] of Byte = (1,2,3,4,5);
...
Check('hi', b, expect);   { compiles fine }

Acceptance

Log