← board

Length on implicit-Self dynamic-array field fails in methods

Symptom

examples/adventure/adventure.pas fails while compiling engine.pas:

pascal26:325: error: Length: undefined variable ()

The failing method code is:

function TMonster.Fight(const guess: AnsiString): Boolean;
begin
  if (CurIdx < 0) or (CurIdx >= Length(Riddles)) then begin Result := True; Exit; end;
  Result := LowerStr(Trim(guess)) = LowerStr(Trim(Riddles[CurIdx].A));
end;

Riddles is a dynamic-array field of TMonster. The same shape works when qualified as Self.Riddles.

Minimal repro:

program implicit_dynfield;
type
  TObj = class
    Items: array of Integer;
    function N: Integer;
  end;

function TObj.N: Integer;
begin
  Result := Length(Items);
end;

var o: TObj;
begin
  o := TObj.Create;
  SetLength(o.Items, 2);
  Writeln(o.N);
end.

Pinned v14 errors at Length(Items). Changing it to Length(Self.Items) compiles and prints 2.

Direction

The normal implicit-field resolver is good enough for scalar field use in methods, but the Length classifier / dynamic-array handling does not preserve the implicit-Self field shape. Route unqualified class fields through the same field-address path used by Self.Field.

Acceptance

Log