← board

SetLength on a nested sub-array slot through a record field

Symptom

SetLength expects an array variable in IR codegen

on SetLength(rec.m[i], n) where m: array of array of Integer is a record field. A local nested SetLength(m[i], n) and a bare-field SetLength(rec.field, n) both already worked.

Cause

The -102 (dyn-array SetLength) lowering had two special paths: (1) a depth>=2 root array symbol (covers local m[i]), and (2) a bare dyn-array field rec.field. An AN_INDEX into a nested-array field (rec.m[i]) is rooted on the record (dyn depth 0, so path 1 misses) and is not a bare field (path 2 misses), so it fell through to the symbol-based generic path, whose IR_LEA-of-a-symbol assumption fails → the error.

Fix

Add a third branch: a non-array-symbol-rooted AN_INDEX target with NodeDynDepth >= 1 routes to IR_SETLEN_DYN via the slot-address path, with leaf element metadata from the dyn-array base (NodeDynBaseTk/NodeDynBaseRec already walk the field+index chain). The array-symbol-rooted nested case keeps the depth>=2 branch (no regression).

Verification

Log