From 8f85878bb2cb2088b08f70ee0cbce5da1dd0f4fa Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Tue, 2 Jun 2026 02:16:13 +0900 Subject: [PATCH] test/951: add str->u8 reject rows at let + struct-field (#251) The reject table exercised the non-foldable element-type branch only at the def site; let and struct-field covered the foldable range branch alone. Add let_str and struct_str so both reject branches (foldable out-of-range int, non-foldable str) fire at all 3 wiring sites. A rune>u8 over-range row stays unexpressible: the lexer caps rune escapes at \xFF and does not decode multi-byte UTF-8 in a rune literal. --- test/wcc/951_arrlit_elem_narrow_run.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/test/wcc/951_arrlit_elem_narrow_run.c b/test/wcc/951_arrlit_elem_narrow_run.c index 6ed92905..f3a7be5b 100644 --- a/test/wcc/951_arrlit_elem_narrow_run.c +++ b/test/wcc/951_arrlit_elem_narrow_run.c @@ -42,11 +42,19 @@ * - struct_int `enc{m=[65,..]}; E.m[0]` → 65 * - struct_rune `enc{m=['A',..]}; E.m[1]` → 66 * - * Reject rows (must FAIL build on BOTH stages — rule-7 loud reject): - * - let_over `let a:[2]u8=[300,1]` (out of range) - * - def_over `def D:[2]u8=[300,1]` (was a wwstage over-accept) - * - struct_over `enc{m=[300,1]}` (was a wwstage over-accept) - * - def_str `def D:[2]u8=["x","y"]` (was a wwstage over-accept) + * Reject rows (must FAIL build on BOTH stages — rule-7 loud reject). + * Two reject branches per the predicate: the FOLDABLE range-check + * (out-of-range int) and the NON-FOLDABLE element-type check (str→u8), + * each exercised at all 3 sites. (A rune>u8 over-range row is not + * expressible: the ww lexer caps rune escapes at \xFF=255 and does not + * decode multi-byte UTF-8 in a rune literal, so every rune literal + * already fits u8 — the foldable branch is identical for int and rune.) + * - let_over `let a:[2]u8=[300,1]` (foldable: out of range) + * - def_over `def D:[2]u8=[300,1]` (foldable: was a ww over-accept) + * - struct_over `enc{m=[300,1]}` (foldable: was a ww over-accept) + * - let_str `let a:[2]u8=["x","y"]` (non-foldable: str→u8) + * - def_str `def D:[2]u8=["x","y"]` (non-foldable: was a ww over-accept) + * - struct_str `enc{m=["x","y"]}` (non-foldable: was a ww over-accept) */ #include #include @@ -116,10 +124,18 @@ static const struct rrow reject_rows[] = { "type enc = struct { m: [2]u8 };\n" "let E: enc = enc { m = [300, 1] };\n" "export fn main() i32 = { return E.m[0]: i32; };\n" }, + { "let_str", + "package main;\n" + "export fn main() i32 = { let a: [2]u8 = [\"x\", \"y\"]; return a[0]: i32; };\n" }, { "def_str", "package main;\n" "def D: [2]u8 = [\"x\", \"y\"];\n" "export fn main() i32 = { return 0; };\n" }, + { "struct_str", + "package main;\n" + "type enc = struct { m: [2]u8 };\n" + "let E: enc = enc { m = [\"x\", \"y\"] };\n" + "export fn main() i32 = { return E.m[0]: i32; };\n" }, { NULL, NULL } };