// Slicing an array whose dimension is a `def` constant // (`[MAX]T`) must resolve the length AND the capacity from the type table, not // the AST dimension node, migrated from test/wcc/989_defdim_slice_run.c (#21). // A `def MAX` dim arrives as a non-literal node; wwstage's cgslice default-hi // fell to MOVQ $0 (len 0 -> underflow, exit 255) and cgbasecap returned false // (cap fell back to len). The fix reads alen from the stamped array tinfo // (rule-13) in both the local and global arms of both helpers. cstage reads the // resolved bu->alen and was always correct; the defcap rows poison cap != len // so a stage that drops the cap word FAILS. T2 keeps the cs==ww net. // // Two def constants (MAX4/MAX6) and two globals (g4/g6) since one package // cannot redeclare `def MAX`; the def-dim path is exercised regardless of name. package defdim_slice_test; def MAX4: i32 = 4; def MAX6: i32 = 6; let g4: [MAX4]u8 = [10, 20, 30, 40]; let g6: [MAX6]u8 = [1, 2, 3, 4, 5, 6]; @test fn deflen_local() void = { // local default-hi: cgslice reads N=4 from tinfo; buf[1:].len = 4-1 = 3. let buf: [MAX4]u8 = [10, 20, 30, 40]; let s: []u8 = buf[1:]; assert(s.len: i32 == 3); }; @test fn deflen_global() void = { // global default-hi: g4[1:].len = 4-1 = 3. let s: []u8 = g4[1:]; assert(s.len: i32 == 3); }; @test fn defcap_local() void = { // cgbasecap local: buf[2:4] over [6]u8 -> len 2, cap = 6-2 = 4 (cap != len). let buf: [MAX6]u8 = [1, 2, 3, 4, 5, 6]; let s: []u8 = buf[2:4]; assert(s.len: i32 == 2); assert(s.cap: i32 == 4); }; @test fn defcap_global() void = { // cgbasecap global: g6[2:4] -> len 2, cap = 6-2 = 4. let s: []u8 = g6[2:4]; assert(s.len: i32 == 2); assert(s.cap: i32 == 4); };