← board

Length of a dynamic array of Char returns 1

Measured

{$mode objfpc}{$H+}
var w: array of Char; d: array of WideChar; b: array of Byte; i: Integer;
begin
  SetLength(w, 6); SetLength(d, 3); SetLength(b, 6);
  for i := 0 to 5 do w[i] := Chr(65 + i);
  WriteLn('char  len=', Length(w), ' high=', High(w));
  WriteLn('wide  len=', Length(d));
  WriteLn('byte  len=', Length(b));
  WriteLn('elems=', w[0], w[5]);
end.
line FPC 3.2.2 pxx
char len= high= 6 / 5 1 / 5
wide len= 3 3
byte len= 6 6
elems= AF AF

The shape of the failure is what makes it worth a ticket rather than a note:

What has already been eliminated

The remaining suspect, unverified: something on the Length path treats an array whose element is Char as a managed string and reads its block header, or converts it through the char-array-to-string wrapper, either of which would yield a one-character answer. Confirm with PXXDBG=a.ir:<proc> before writing a cause into this ticket — devdocs/dev/root-cause-over-microfix.md, and the standing rule that every wrong root cause in this repo was a plausible story nobody diffed against an oracle.

Gate

make compiler/pascal26 + the program above matching FPC on all four lines.

Log