Files
ww/test/lang/arraytoslice_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

81 lines
1.9 KiB
Plaintext

// #258: the implicit [N]T -> []T array-to-slice BORROW at
// assign / return / call-arg / let init (.ptr = &arr[0], .len = .cap = N).
// Migrated from test/wcc/953_arraytoslice_run.c (value rows; cs==ww byte-id
// rides T2). The element-type-mismatch reject rows stay as runww //ww:error
// carriers under test/wcc/data/.
//
// The fix is a checker-only desugar to the explicit full slice arr[0:len(arr)];
// cgen is untouched. Each row asserts through .ptr-deref (indexing) AND .cap,
// not just .len — a wrong borrow with the right len but a wrong ptr/cap would
// otherwise pass. borrow_i32 mutates through the slice and reads the backing
// array (alias, not copy).
package arraytoslice_test;
let g: [3]i32 = [7, 8, 9];
fn mk() []i32 = { return g; };
fn sum_i32(s: []i32) i32 = {
assert(s.cap == 4);
let t: i32 = 0; let i: i32 = 0;
for (i < s.len) { t += s[i]; i += 1; };
return t;
};
fn sum_u8(s: []u8) i32 = {
assert(s.cap == 3);
let t: i32 = 0; let i: i32 = 0;
for (i < s.len) { t += s[i]: i32; i += 1; };
return t;
};
@test fn let_i32() void = {
let a: [4]i32 = [11, 22, 33, 44];
let s: []i32 = a;
assert(s[2] == 33);
assert(s.len == 4);
assert(s.cap == 4);
};
@test fn let_u8() void = {
let a: [4]u8 = [11u8, 22u8, 33u8, 66u8];
let s: []u8 = a;
assert(s[3]: i32 == 66);
assert(s.len == 4);
assert(s.cap == 4);
};
@test fn assign_i32() void = {
let a: [4]i32 = [1, 2, 3, 4];
let s: []i32 = a[0:1];
s = a;
assert(s[3] == 4);
assert(s.len == 4);
assert(s.cap == 4);
};
@test fn callarg_i32() void = {
let a: [4]i32 = [10, 20, 30, 5];
assert(sum_i32(a) == 65);
};
@test fn callarg_u8() void = {
let a: [3]u8 = [10u8, 20u8, 40u8];
assert(sum_u8(a) == 70);
};
@test fn return_i32() void = {
let s: []i32 = mk();
assert(s.len == 3);
assert(s.cap == 3);
assert(s[1] + s[2] == 17);
};
@test fn borrow_i32() void = {
let a: [4]i32 = [1, 2, 3, 4];
let s: []i32 = a;
s[2] = 55;
assert(a[2] == 55);
};