Files
ww/test/lang/defdim_slice_test.ww
Hojun-Cho 83f5956df2 test: banner purge + WHY-only comment sweep (rule 8)
Every section banner dies (103 -> 0) across test/lang, the observer
suites, the C carriers, and the five comment-heavy corpus fixtures;
banner provenance (#N cites, carrier numbers, repair-cluster labels)
folded into headers or adjacent WHY comments. Narration deleted; row
provenance, ref cites, divergence pins, and layout contracts kept
(fwd-ref decl-order guards and bootstrap-gate corpus rationale
restored where the sweep over-cut). Comment-only proven: all 3742
wwbuild workdir .s byte-identical before/after; test-commit and
test-byteid (161 lang + 1399 data, 0 pinned-divergent) green.
2026-08-08 21:40:23 +09:00

48 lines
1.7 KiB
Plaintext

// 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);
};