test: migrate 802_lenidx to @test + runww rejects, retire C twin (fold-3)

#19 len/index family: value rows -> test/lang/lenidx_test.ww (primitive-only asserts), 3 reject (callres/sliceexpr/strlit) -> runww //ww:error dual-stage carriers. byteid floor 52->53.
This commit is contained in:
2026-06-22 16:53:49 +09:00
parent 057e805cf0
commit 04f163dde6
6 changed files with 174 additions and 427 deletions

139
test/lang/lenidx_test.ww Normal file
View File

@@ -0,0 +1,139 @@
// lenidx_test — the `len()` builtin over a non-IDENT operand shape (#19, then
// the C5 sweep #10 F2 + #41 FA2/FB1), migrated from test/wcc/802_lenidx_run.c.
// `len(xs[i])` / `len(*p)` / `len(s.field)` etc. once fell to a bare cgexpr
// fallback that left AX = the slice/str DATA POINTER, so len() returned the
// PTR as the length — silent ptr-garbage, byte-identical in BOTH stages (the
// bootstrap corpus never indexes-then-len()s an element, so byte-id was
// blind). The fix routes every place-resolvable operand through one uniform
// header-place arm (.len at place+8) in both stages; non-place operands
// (string literal, slicing expr, call result) now die LOUD (rule 7) — those
// three are the runww reject carriers. The empty/zero rows are the strongest
// pins: a leaked ptr is nonzero, so `len(empty) == 0` catches the regression
// where a bare exit code couldn't. PRIMITIVE-only asserts (no fmt/strconv) so
// a co-miscompile in the assert path cannot mask the bug. The .len/.ptr
// pseudo-field control pins that the fix left the already-correct field paths
// untouched. T2 keeps cs==ww (the #19 lineage: len of an INDEXED element is
// exactly where cs!=ww would surface).
package lenidx_test;
// global [N]str table — the exact #19 repro operand (static-init str array,
// #18 family); referenced from several rows to keep the global codegen path.
let t: [3]str = ["a", "bcd", ""];
type S = struct { pad: i64, name: str };
@test fn lenidx_arrtab_mid() void = {
// len(t[1]) == 3; pre-fix this returned a ptr low-byte, not 3.
assert(len(t[1]) == 3);
};
@test fn lenidx_arrtab_empty() void = {
// empty element: a leaked ptr is nonzero, len must be 0.
assert(len(t[2]) == 0);
};
@test fn lenidx_arrtab_first() void = {
// guards an off-by-one in the index scale.
assert(len(t[0]) == 1);
};
fn slen(xs: []str, i: i64) int = { return len(xs[i]): int; };
@test fn lenidx_slice_param_sum() void = {
// len(xs[i]) over a []str slice ARG (callee-side shape), 1 + 3 + 0 == 4.
let arr: [3]str = ["a", "bcd", ""];
let xs: []str = arr;
assert(slen(xs, 0) + slen(xs, 1) + slen(xs, 2) == 4);
};
@test fn lenidx_neg_control_field_agree() void = {
// the `.len` pseudo-field on the same indexed element must agree with
// len(), AND `.ptr` must still deref to the first byte — the fix must
// leave the already-correct .len/.ptr field paths untouched.
assert(len(t[1]) == t[1].len);
let p: *u8 = t[1].ptr;
assert(*p == 'b');
assert(len(t[1]) == 3);
};
fn derefn(p: *[]i64) int = { return len(*p): int; };
@test fn lenidx_deref_param() void = {
// len(*p) through a *[]T PARAM (FB1) loaded the header's word 0 (the
// data pointer) as the length.
let xs: []i64 = [10, 20, 30];
assert(derefn(&xs) == 3);
};
@test fn lenidx_deref_local() void = {
let xs: []i64 = [10, 20, 30];
let p: *[]i64 = &xs;
assert(len(*p) == 3);
};
@test fn lenidx_deref_empty() void = {
// EMPTY-slice deref: the off-by-header bug returns .ptr (nonzero),
// len() must say 0 — only a non-exit primitive assert pins this.
let xs: []i64 = [1];
let ys: []i64 = xs[0:0];
let p: *[]i64 = &ys;
assert(len(*p) == 0);
};
@test fn lenidx_deref_chain() void = {
// chained deref len(**pp) — the resolver spine must recurse both hops.
let xs: []i64 = [10, 20, 30];
let p: *[]i64 = &xs;
let pp: **[]i64 = &p;
assert(len(**pp) == 3);
};
@test fn lenidx_idx_field() void = {
// len(xs[i].field) (F2) — N_DOT over an N_INDEX base matched no arm.
let xs: [2]S = [S{ pad = 1, name = "a" }, S{ pad = 2, name = "bcde" }];
assert(len(xs[1].name) == 4);
};
fn derefidxn(p: *[]S, i: i64) int = { return len((*p)[i].name): int; };
@test fn lenidx_deref_idx_field() void = {
// full deref spine: len((*p)[i].field).
let arr: [2]S = [S{ pad = 1, name = "a" }, S{ pad = 2, name = "bcde" }];
let xs: []S = arr;
assert(derefidxn(&xs, 1) == 4);
};
fn derefidxcn(p: *[]S, i: i64) int = { return len((*p)[i + 1].name): int; };
@test fn lenidx_deref_idx_field_computed() void = {
// computed index through the spine — i+1 must resolve like a constant.
let arr: [2]S = [S{ pad = 1, name = "a" }, S{ pad = 2, name = "bcde" }];
let xs: []S = arr;
assert(derefidxcn(&xs, 0) == 4);
};
@test fn lenidx_dot_field() void = {
// len(s.field) — the #235 arm's inner non-tuple fallback was ptr-garbage.
let s: S = S{ pad = 7, name = "abc" };
assert(len(s.name) == 3);
};
@test fn lenidx_ptr_field() void = {
// len(p.field) through a *struct.
let s: S = S{ pad = 7, name = "abc" };
let p: *S = &s;
assert(len(p.name) == 3);
};
@test fn lenidx_neutral_array_const() void = {
// neutrality control — the [N]T const fast-path still holds.
let a: [5]u8 = [1, 2, 3, 4, 5];
assert(len(a) == 5);
};
@test fn lenidx_neutral_ident_str() void = {
// neutrality control — the ident-str fast-path still holds.
let s: str = "abcd";
assert(len(s) == 4);
};

View File

@@ -1,417 +0,0 @@
/*
* 802_lenidx_run — BUG #19. Runtime + cs==ww byte-id net for the
* `len()` builtin applied to an INDEXED str/slice element (`len(xs[i])`).
*
* THE BUG (cstage == wwstage, BOTH wrong — shared gap, NOT rule-10):
* `len(t[i])` over a `[N]str` / `[]str` returned the element's .ptr,
* not its length. The len() builtin (cgen.c / cgenexpr.ww) had arms for
* an N_IDENT slice/str operand (.len at BP+off+8), a tuple-element N_DOT
* (#235), and a whole TY_ARRAY (→ alen) — but NOT an N_INDEX element.
* So `len(xs[i])` fell to the bare `cgexpr(arg)` fallback, which loads
* the str/slice element header via cgslicehdr leaving AX=.ptr, BX=.len,
* CX=.cap — and len() then returned AX (the ptr) AS the length. Same
* family as #14 (literal `.len` returned ptr) and #18 (shared static-init
* gap). byte-id was BLIND: no bootstrap source uses len(indexed-element)
* — the corpus indexes-then-reads .len explicitly or hardcodes lengths.
* CONTRAST (controls, all already correct): `t[i].len` pseudo-field,
* `t[i].ptr`, and scalar `len(s)` over a bare str variable.
*
* THE FIX (#19): add an N_INDEX arm to the len() builtin in BOTH stages —
* `cgexpr(arg)` to materialise the element, then `MOVQ BX, AX` to shuffle
* the len word (already in BX after cgslicehdr) into the result reg. The
* same MOVQ BX,AX shape as #14's `.len` pseudo-field fix. Covers str AND
* slice elements (both are 24B headers loaded by cgslicehdr).
*
* EACH ROW CARRIES BOTH DIMENSIONS (801 model):
* (a) cstage `ww build` + run, asserting the exit — pins that the
* converged asm is runtime-correct (real lengths, not ptr bytes).
* (b) w6c vs w6c_ww `.s` cmp — FAILS if the stages diverge (rule-10).
*
* GATE POLARITY: must stay GREEN. A wrong exit means len(indexed-element)
* regressed back to returning the ptr; a byte-id FAIL means the stages
* diverged.
*
* SCOPE NOTE: the []T (slice-of-slice) ELEMENT len shares the identical
* codegen path (cgslicehdr → BX=len → MOVQ BX,AX) and is byte-id-clean in
* isolation, but a clean runtime row for it is blocked by a SEPARATE
* pre-existing bug — the `[2][]u8` array-literal → slice coercion emits a
* divergent frame offset (cstage -24(BP) vs wwstage -40(BP)). That gap is
* unrelated to len() (it reproduces with the `.len` pseudo-field too) and
* is filed separately; these rows stay on str elements to avoid it.
*
* C5 SWEEP (#10 F2 + #41 FA2/FB1): the arm enumeration leaked FOUR
* siblings over time (#235 → #19 → F2 → FA2/FB1) — every unhandled
* operand shape fell to a bare cgexpr fallback returning the slice DATA
* POINTER as the length, silent and byte-id-blind. The fix replaces the
* fallback with ONE uniform header-place route (cgplaceaddr → .len at
* place+8) in BOTH stages; non-place operands (string literal, slicing
* expr, call result — all previously the same silent ptr-garbage) now
* die LOUD (rule 7). Rows below pin: len(*p) param + local (FB1),
* len(*p) on an EMPTY slice (a bare exit-code row can't pin this — the
* garbage ptr's low byte masks to 0 — hence the branchy discriminator),
* len(**pp) (chained deref, same resolver spine), len(xs[i].field)
* (F2), len((*p)[i].field) incl. computed index, len(s.field) +
* len(p.field) (struct-field cousins), the [N]T-const and ident-str
* neutrality controls (global and tuple fast-paths have dedicated runs:
* 797, 903), and reject rows with the exact rule-7 text. All
* garbage/reject rows verified FAILING at the parent e481cb8 (the
* per-row garbage exits below cite the d642017 probes; garbage is
* frame-layout-dependent and drifts between commits — the FAILING
* status is the pin, not the value).
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/wait.h>
static int
runwait(const char *cmd)
{
int rc = system(cmd);
if (rc == -1) return -1;
if (WIFEXITED(rc)) return WEXITSTATUS(rc);
return -1;
}
/* reject != NULL marks a build-reject row: both stages must refuse the
* source LOUD and the diagnostic must contain that exact text. */
struct row { const char *label; const char *src; int want_exit;
const char *reject; };
static const struct row rows[] = {
/* the exact #19 repro: a [3]str table, len(t[1]) == 3. Pre-fix this
* returned a ptr low-byte (58), not 3. */
{ "arrtab_mid",
"package main;\n"
"let t: [3]str = [\"a\", \"bcd\", \"\"];\n"
"export fn main() i32 = { return len(t[1]): i32; };\n", 3 },
/* empty-string element edge: len(t[2]) == 0 (a ptr would be nonzero). */
{ "arrtab_empty",
"package main;\n"
"let t: [3]str = [\"a\", \"bcd\", \"\"];\n"
"export fn main() i32 = { return len(t[2]): i32; };\n", 0 },
/* first element: len(t[0]) == 1 — guards an off-by-one in the index
* scale (a ptr or the wrong element would not be 1). */
{ "arrtab_first",
"package main;\n"
"let t: [3]str = [\"a\", \"bcd\", \"\"];\n"
"export fn main() i32 = { return len(t[0]): i32; };\n", 1 },
/* []str slice parameter — the callee-side shape: len(xs[i]) over a
* slice arg, summing all three lengths (1 + 3 + 0 == 4). */
{ "slice_param_sum",
"package main;\n"
"fn slen(xs: []str, i: i64) i32 = { return len(xs[i]): i32; };\n"
"export fn main() i32 = {\n"
" let arr: [3]str = [\"a\", \"bcd\", \"\"];\n"
" let xs: []str = arr;\n"
" return slen(xs, 0) + slen(xs, 1) + slen(xs, 2);\n"
"};\n", 4 },
/* NEGATIVE CONTROL: the `.len` pseudo-field on the same indexed
* element must agree with len() (both == 3), AND `.ptr` must still
* deref to the first byte ('b' == 98) — proving the fix left the
* already-correct .len/.ptr field paths untouched. Returns 3 only if
* len()==.len AND *.ptr=='b'. */
{ "neg_control_field_agree",
"package main;\n"
"let t: [3]str = [\"a\", \"bcd\", \"\"];\n"
"export fn main() i32 = {\n"
" if (len(t[1]) != t[1].len) { return 91; };\n"
" let p: *u8 = t[1].ptr;\n"
" if (*p != 'b') { return 92; };\n"
" return len(t[1]): i32;\n"
"};\n", 3 },
/* ---- C5 sweep rows (#10 F2 + #41 FA2/FB1) ---- */
/* FB1 exact repro: len(*p) through a *[]T PARAM loaded the slice
* header's word 0 (the data pointer) as the length — silent
* ptr-garbage (exit 48 at d642017), byte-id both stages. */
{ "deref_param",
"package main;\n"
"fn n(p: *[]i64) i32 = { return len(*p): i32; };\n"
"export fn main() i32 = {\n"
" let xs: []i64 = [10, 20, 30];\n"
" return n(&xs);\n"
"};\n", 3, NULL },
/* FB1, local-ptr variant (exit 64 at d642017). */
{ "deref_local",
"package main;\n"
"export fn main() i32 = {\n"
" let xs: []i64 = [10, 20, 30];\n"
" let p: *[]i64 = &xs;\n"
" return len(*p): i32;\n"
"};\n", 3, NULL },
/* EMPTY-slice deref: the off-by-header bug returns .ptr (nonzero),
* len() must say 0. A bare exit row can't pin it — the garbage
* ptr's low byte happens to mask to 0 (verified at e481cb8) — so
* branch on len()!=0 and return distinct codes. */
{ "deref_empty",
"package main;\n"
"fn n(p: *[]i64) i32 = {\n"
" if (len(*p) != 0) { return 9; };\n"
" return 42;\n"
"};\n"
"export fn main() i32 = {\n"
" let xs: []i64 = [1];\n"
" let ys: []i64 = xs[0:0];\n"
" return n(&ys);\n"
"};\n", 42, NULL },
/* chained deref len(**pp) — the resolver spine must recurse through
* BOTH hops (exit 208 garbage at e481cb8). */
{ "deref_chain",
"package main;\n"
"export fn main() i32 = {\n"
" let xs: []i64 = [10, 20, 30];\n"
" let p: *[]i64 = &xs;\n"
" let pp: **[]i64 = &p;\n"
" return len(**pp): i32;\n"
"};\n", 3, NULL },
/* F2 exact repro: len(xs[i].field) — N_DOT over an N_INDEX base
* matched no arm (the #235 arm requires an IDENT base) and fell to
* the ptr-garbage fallback (exit 147 at d642017). */
{ "idx_field",
"package main;\n"
"type S = struct { pad: i64, name: str };\n"
"export fn main() i32 = {\n"
" let xs: [2]S = [S{ pad = 1, name = \"a\" }, S{ pad = 2, name = \"bcde\" }];\n"
" return len(xs[1].name): i32;\n"
"};\n", 4, NULL },
/* full deref spine: len((*p)[i].field) (exit 10 at d642017). */
{ "deref_idx_field",
"package main;\n"
"type S = struct { pad: i64, name: str };\n"
"fn n(p: *[]S, i: i64) i32 = { return len((*p)[i].name): i32; };\n"
"export fn main() i32 = {\n"
" let arr: [2]S = [S{ pad = 1, name = \"a\" }, S{ pad = 2, name = \"bcde\" }];\n"
" let xs: []S = arr;\n"
" return n(&xs, 1);\n"
"};\n", 4, NULL },
/* computed index through the spine — cgplaceaddr cgexpr's the index
* operand, so i+1 must resolve identically to a constant. */
{ "deref_idx_field_computed",
"package main;\n"
"type S = struct { pad: i64, name: str };\n"
"fn n(p: *[]S, i: i64) i32 = { return len((*p)[i + 1].name): i32; };\n"
"export fn main() i32 = {\n"
" let arr: [2]S = [S{ pad = 1, name = \"a\" }, S{ pad = 2, name = \"bcde\" }];\n"
" let xs: []S = arr;\n"
" return n(&xs, 0);\n"
"};\n", 4, NULL },
/* struct-field cousins: len(s.field) (exit 75 at d642017) and
* len(p.field) through a *struct (exit 87 at d642017) — the #235
* arm's inner non-tuple fallback was the same ptr-garbage. */
{ "dot_field",
"package main;\n"
"type S = struct { pad: i64, name: str };\n"
"export fn main() i32 = {\n"
" let s: S = S{ pad = 7, name = \"abc\" };\n"
" return len(s.name): i32;\n"
"};\n", 3, NULL },
{ "ptr_field",
"package main;\n"
"type S = struct { pad: i64, name: str };\n"
"export fn main() i32 = {\n"
" let s: S = S{ pad = 7, name = \"abc\" };\n"
" let p: *S = &s;\n"
" return len(p.name): i32;\n"
"};\n", 3, NULL },
/* neutrality controls — already correct pre-sweep, pin that the
* enumerated fast-paths ([N]T const fold, ident str) still hold. */
{ "neutral_array_const",
"package main;\n"
"export fn main() i32 = {\n"
" let a: [5]u8 = [1, 2, 3, 4, 5];\n"
" return len(a): i32;\n"
"};\n", 5, NULL },
{ "neutral_ident_str",
"package main;\n"
"export fn main() i32 = {\n"
" let s: str = \"abcd\";\n"
" return len(s): i32;\n"
"};\n", 4, NULL },
/* non-place operands: previously the same SILENT ptr-garbage
* (strlit exit 40, slice-expr exit 48, call-result exit 0 at
* master); now LOUD per rule 7 in both stages. */
{ "reject_strlit",
"package main;\n"
"export fn main() i32 = { return len(\"abc\"): i32; };\n",
0, "#10/#41: len() operand shape not place-resolvable (rule-7)" },
{ "reject_sliceexpr",
"package main;\n"
"export fn main() i32 = {\n"
" let xs: []i64 = [10, 20, 30, 40];\n"
" return len(xs[1:3]): i32;\n"
"};\n",
0, "#10/#41: len() operand shape not place-resolvable (rule-7)" },
{ "reject_callres",
"package main;\n"
"fn mk() []i64 = {\n"
" let xs: []i64 = [10, 20, 30];\n"
" return xs;\n"
"};\n"
"export fn main() i32 = { return len(mk()): i32; };\n",
0, "#10/#41: len() operand shape not place-resolvable (rule-7)" },
{ NULL, NULL, 0, NULL }
};
static int
file_contains(const char *path, const char *needle)
{
FILE *f = fopen(path, "rb");
if (!f) return 0;
char buf[8192];
size_t got = fread(buf, 1, sizeof buf - 1, f);
buf[got] = '\0';
fclose(f);
return strstr(buf, needle) != NULL;
}
static int
slurp_eq(const char *a, const char *b)
{
FILE *fa = fopen(a, "rb");
FILE *fb = fopen(b, "rb");
if (!fa || !fb) { if (fa) fclose(fa); if (fb) fclose(fb); return -1; }
int rc = 0;
for (;;) {
int ca = fgetc(fa);
int cb = fgetc(fb);
if (ca != cb) { rc = -1; break; }
if (ca == EOF) break;
}
fclose(fa); fclose(fb);
return rc;
}
int
main(void)
{
const char *bin = getenv("BIN");
if (!bin) bin = "out/bin";
char absbin[1024];
if (bin[0] != '/') {
char cwd[1024];
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin);
bin = absbin;
}
char w6c[1100], w6c_ww[1100];
snprintf(w6c, sizeof w6c, "%s/w6c", bin);
snprintf(w6c_ww, sizeof w6c_ww, "%s/w6c_ww", bin);
if (access(w6c_ww, X_OK) != 0) {
fprintf(stderr, "lenidx: w6c_ww missing — cannot run the "
"cs==ww byte-id gate\n");
return 1;
}
int n = 0, fail = 0;
for (int i = 0; rows[i].src; i++, n++) {
char src[64];
snprintf(src, sizeof src, "/tmp/wwli_%d_%d.ww", getpid(), i);
FILE *f = fopen(src, "wb");
if (f == NULL) { fail++; continue; }
fputs(rows[i].src, f);
fclose(f);
/* reject rows: BOTH stages must refuse with the exact rule-7
* text — a silent accept means the ptr-garbage fallback is
* back. */
if (rows[i].reject) {
char errf[64], cmd2[2048];
int bad = 0;
snprintf(errf, sizeof errf, "/tmp/wwli_%d_%d.err",
getpid(), i);
snprintf(cmd2, sizeof cmd2, "%s -o /dev/null %s 2>%s",
w6c, src, errf);
if (runwait(cmd2) == 0) {
fprintf(stderr, "row[%s]: w6c ACCEPTED a "
"reject row\n", rows[i].label);
bad = 1;
} else if (!file_contains(errf, rows[i].reject)) {
fprintf(stderr, "row[%s]: w6c rejected but "
"without the rule-7 text\n",
rows[i].label);
bad = 1;
}
snprintf(cmd2, sizeof cmd2, "%s -o /dev/null %s 2>%s",
w6c_ww, src, errf);
if (runwait(cmd2) == 0) {
fprintf(stderr, "row[%s]: w6c_ww ACCEPTED a "
"reject row\n", rows[i].label);
bad = 1;
} else if (!file_contains(errf, rows[i].reject)) {
fprintf(stderr, "row[%s]: w6c_ww rejected but "
"without the rule-7 text\n",
rows[i].label);
bad = 1;
}
if (bad) fail++;
unlink(errf); unlink(src);
continue;
}
/* (a) cstage build + run in a scratch dir. */
char tmpdir[64];
snprintf(tmpdir, sizeof tmpdir, "/tmp/wwli_%d_d_%d", getpid(), i);
mkdir(tmpdir, 0755);
char cmd[2048];
snprintf(cmd, sizeof cmd, "cd %s && %s/ww build %s",
tmpdir, bin, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: cstage build failed\n",
rows[i].label);
fail++;
unlink(src); rmdir(tmpdir);
continue;
}
char outbin[128];
const char *base = strrchr(src, '/');
base = base ? base + 1 : src;
snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base);
char *dot = strrchr(outbin, '.');
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
int got = runwait(outbin);
if (got != rows[i].want_exit) {
fprintf(stderr, "row[%s]: cstage exit %d, want %d\n",
rows[i].label, got, rows[i].want_exit);
fail++;
}
unlink(outbin); rmdir(tmpdir);
/* (b) cs==ww byte-id gate. */
char cs_s[64], ws_s[64];
snprintf(cs_s, sizeof cs_s, "/tmp/wwli_%d_%d_cs.s", getpid(), i);
snprintf(ws_s, sizeof ws_s, "/tmp/wwli_%d_%d_ww.s", getpid(), i);
snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label);
fail++; unlink(src); continue;
}
snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null",
w6c_ww, ws_s, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label);
fail++; unlink(src); unlink(cs_s); continue;
}
if (slurp_eq(cs_s, ws_s) != 0) {
fprintf(stderr, "row[%s]: cstage/wwstage .s DIFFER "
"(rule-10 byte-id violation)\n", rows[i].label);
fail++;
}
unlink(src); unlink(cs_s); unlink(ws_s);
}
if (fail) {
fprintf(stderr, "%d/%d lenidx tests failed\n", fail, n);
return 1;
}
printf("lenidx: %d/%d ok (cstage run + cs==ww byte-id)\n", n, n);
return 0;
}

View File

@@ -0,0 +1,13 @@
//ww:error "len() operand shape not place-resolvable (rule-7)"
// Lifted from test/wcc/802_lenidx_run.c reject row "reject_callres"
// (#10/#41/rule-7): len() over a CALL RESULT (`mk()`) is not a
// place-resolvable operand and MUST loud-fail in both stages, not silently
// return the data pointer as the length. The substring is the shared
// diagnostic body — byte-identical on both stages (no file:line, no cstage
// "ww: " prefix — both differ cs vs ww).
package main;
fn mk() []i64 = {
let xs: []i64 = [10, 20, 30];
return xs;
};
export fn main() i32 = { return len(mk()): i32; };

View File

@@ -0,0 +1,12 @@
//ww:error "len() operand shape not place-resolvable (rule-7)"
// Lifted from test/wcc/802_lenidx_run.c reject row "reject_sliceexpr"
// (#10/#41/rule-7): len() over a SLICING expression (`xs[1:3]`) is not a
// place-resolvable operand and MUST loud-fail in both stages, not silently
// return the data pointer as the length. The substring is the shared
// diagnostic body — byte-identical on both stages (no file:line, no cstage
// "ww: " prefix — both differ cs vs ww).
package main;
export fn main() i32 = {
let xs: []i64 = [10, 20, 30, 40];
return len(xs[1:3]): i32;
};

View File

@@ -0,0 +1,9 @@
//ww:error "len() operand shape not place-resolvable (rule-7)"
// Lifted from test/wcc/802_lenidx_run.c reject row "reject_strlit"
// (#10/#41/rule-7): len() over a string LITERAL is not a place-resolvable
// operand and MUST loud-fail in both stages, not silently return the data
// pointer as the length. The substring is the shared diagnostic body —
// byte-identical on both stages (no file:line, no cstage "ww: " prefix —
// both differ cs vs ww).
package main;
export fn main() i32 = { return len("abc"): i32; };