wcc/ww: match-as-expression unifies arm yields (coarse-family gate)
exprtype N_MATCH took the first arm's yield type without walking the rest — int-vs-str arms silently produced garbage downstream. Walk all arms: typeeq-equal accepts; a definite coarse-family mismatch (num/str/bool via the new yieldclass classifier, unknown classes stay lenient) rejects. Same-family non-assignable pairs remain lenient — the documented precision residual is task #52 (needs tinfo-level type_assignable). The wave's table-driven reject test lands here: 989_catA_f2_reject, 19 rows x 2 stages, each member pre-fix-red-proven.
This commit is contained in:
374
test/wcc/989_catA_f2_reject.c
Normal file
374
test/wcc/989_catA_f2_reject.c
Normal file
@@ -0,0 +1,374 @@
|
||||
/*
|
||||
* 989_catA_f2_reject — #38/F2 checker-reject wave: align the wwstage
|
||||
* checker UP to cstage's harec-faithful rejects (cat-A silent-accept
|
||||
* family from the 2026-06-11 stability review). Each row is a program
|
||||
* cstage loud-rejects but pre-fix wwstage silently accepted (then built
|
||||
* a wrong binary). The build-based reject-matrix idiom (sibling
|
||||
* 989_callarg_typecheck.c): a REJECT row must FAIL to build on every
|
||||
* driver; an ACCEPT control must build + run to its expected exit.
|
||||
*
|
||||
* Members (review item → check.ww seam → cstage twin):
|
||||
* #2 arrayelen non-const dim tinfofornode N_TARRAY check.c:715
|
||||
* #6 binoptype/unoptype kinds binoptype/unoptype check.c:1186-1238
|
||||
* #7 size/align unknown type size intercept check.c:93/1538
|
||||
* #10 tuple-literal arity checktuplearrfits type.c:416/check.c:2386
|
||||
* #39 non-tuple massign rhs N_MASSIGN resolvewalk check.c:2562
|
||||
* #8 checktryprop spread-blind trycountvariants check.c:2160 (F3)
|
||||
* #6' match-yield unification exprtype N_MATCH check.c:2080
|
||||
*
|
||||
* Rule-10: every row runs on cstage `ww` and, when present, wwstage
|
||||
* `ww_ww`; both must agree. wwstage rows are gated on out/bin/ww_ww.
|
||||
*/
|
||||
#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;
|
||||
}
|
||||
|
||||
struct row {
|
||||
const char *label;
|
||||
const char *src;
|
||||
int expect_build; /* 1 = build+run to want_exit; 0 = must FAIL */
|
||||
int want_exit;
|
||||
};
|
||||
|
||||
static const struct row rows[] = {
|
||||
/* #2 — a runtime-valued array dimension is non-const → REJECT. Pre-fix
|
||||
* wwstage folded it to a 0-sized slot aliasing the dim variable. */
|
||||
{ "arrlen_runtime",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let n: i32 = 3;\n"
|
||||
" let xs: [n]u8;\n"
|
||||
" xs[0] = 77u8;\n"
|
||||
" return n;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
|
||||
/* #2 control — a literal dimension stays valid → run 0. */
|
||||
{ "arrlen_const_ok",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let xs: [3]u8;\n"
|
||||
" xs[0] = 1u8;\n"
|
||||
" return 0;\n"
|
||||
"};\n",
|
||||
1, 0 },
|
||||
|
||||
/* #6 — str + str is arithmetic on a non-numeric → REJECT. Pre-fix
|
||||
* wwstage emitted an integer ADD of the two header pointers. */
|
||||
{ "str_plus_str",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let a: str = \"x\";\n"
|
||||
" let b: str = \"y\";\n"
|
||||
" let c: str = a + b;\n"
|
||||
" return c.len: i32;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
|
||||
/* #6 — bitwise & on str is non-integer → REJECT. */
|
||||
{ "str_bitand",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let a: str = \"x\";\n"
|
||||
" let b: str = \"y\";\n"
|
||||
" let n: i32 = (a & b): i32;\n"
|
||||
" return n;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
|
||||
/* #6 — ordered comparison on str is non-numeric → REJECT (EQ/NEQ stay
|
||||
* valid; only the ordered <,<=,>,>= are gated, matching cstage). */
|
||||
{ "str_lt",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let a: str = \"x\";\n"
|
||||
" let b: str = \"y\";\n"
|
||||
" if (a < b) { return 1; };\n"
|
||||
" return 0;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
|
||||
/* #6 — unary ~ on a non-integer (str) → REJECT. */
|
||||
{ "tilde_str",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let a: str = \"x\";\n"
|
||||
" let n: i32 = (~a): i32;\n"
|
||||
" return n;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
|
||||
/* #6 control — integer arithmetic, comparison, bitwise all valid. */
|
||||
{ "int_ops_ok",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let a: i32 = 3;\n"
|
||||
" let b: i32 = 4;\n"
|
||||
" let c: i32 = (a + b) & 7;\n"
|
||||
" if (a < b) { c = c + 1; };\n"
|
||||
" return c;\n"
|
||||
"};\n",
|
||||
1, 8 },
|
||||
|
||||
/* #7 — size() of a value (not a type) is an unknown type → REJECT.
|
||||
* Pre-fix wwstage folded the unresolved name to 0 silently. */
|
||||
{ "size_localvar",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let v: i32 = 5;\n"
|
||||
" return size(v): i32;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
|
||||
/* #7 control — size() of a real type folds → run 4. */
|
||||
{ "size_type_ok",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = { return size(i32): i32; };\n",
|
||||
1, 4 },
|
||||
|
||||
/* #10 — an over-long tuple literal → REJECT. */
|
||||
{ "tuple_overlong",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let t: (i32, i32) = (1, 2, 3);\n"
|
||||
" return 0;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
|
||||
/* #10 — a short tuple literal → REJECT (the live miscompile: cgen
|
||||
* filled the missing slot with a stale register). */
|
||||
{ "tuple_short",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let t: (i32, i32, i32) = (1, 2);\n"
|
||||
" return 0;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
|
||||
/* #10 control — a matching-arity tuple literal → run 3. */
|
||||
{ "tuple_match_ok",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let t: (i32, i32) = (1, 2);\n"
|
||||
" return t.0 + t.1;\n"
|
||||
"};\n",
|
||||
1, 3 },
|
||||
|
||||
/* #39 — multi-assign rhs is a tuple ALIAS, not a bare tuple → REJECT
|
||||
* (cstage does not chase the NAMED wrapper here; nor does ww). */
|
||||
{ "massign_alias",
|
||||
"package main;\n"
|
||||
"type pair = (i64, str);\n"
|
||||
"fn f() pair = { return (7i64, \"hey\"); };\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let a: i64 = 0i64;\n"
|
||||
" let s: str = \"\";\n"
|
||||
" a, s = f();\n"
|
||||
" return 0;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
|
||||
/* #39 — multi-assign rhs is a plain scalar, not a tuple → REJECT. */
|
||||
{ "massign_scalar",
|
||||
"package main;\n"
|
||||
"fn g() i64 = { return 7i64; };\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let a: i64 = 0i64;\n"
|
||||
" let s: i64 = 0i64;\n"
|
||||
" a, s = g();\n"
|
||||
" return 0;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
|
||||
/* #39 control — a bare-tuple-returning fn drives a valid massign. */
|
||||
{ "massign_tuple_ok",
|
||||
"package main;\n"
|
||||
"fn f() (i64, i64) = { return (3i64, 4i64); };\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let a: i64 = 0i64;\n"
|
||||
" let b: i64 = 0i64;\n"
|
||||
" a, b = f();\n"
|
||||
" return (a + b): i32;\n"
|
||||
"};\n",
|
||||
1, 7 },
|
||||
|
||||
/* #8 — a `...inner` spread makes the union multi-success; the F8 gate
|
||||
* must fire over the FLATTENED members → REJECT. Pre-fix wwstage counted
|
||||
* the spread as one success (nsucc=1) and silently accepted. */
|
||||
{ "try_spread_multisuccess",
|
||||
"package main;\n"
|
||||
"type inner = (i32 | bool);\n"
|
||||
"type e = !void;\n"
|
||||
"fn g() (...inner | e) = { return true; };\n"
|
||||
"export fn main() i32 = { let x = g()!; return 0; };\n",
|
||||
0, 0 },
|
||||
|
||||
/* #8 control — a single-success tagged union try unwraps fine → run 5. */
|
||||
{ "try_single_ok",
|
||||
"package main;\n"
|
||||
"type e = !void;\n"
|
||||
"fn g() (i32 | e) = { return 5; };\n"
|
||||
"export fn main() i32 = { let x = g()!; return x; };\n",
|
||||
1, 5 },
|
||||
|
||||
/* match-yield — arms yielding incompatible types (int vs str) → REJECT.
|
||||
* Pre-fix wwstage took the first arm's type and ran the str arm's pointer
|
||||
* through an int-stamped slot. */
|
||||
{ "match_mixed_yield",
|
||||
"package main;\n"
|
||||
"fn pick(b: bool) (i32 | str) = { if (b) { return 7; }; return \"x\"; };\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let v: (i32 | str) = pick(true);\n"
|
||||
" let r = match (v) { case i32 => yield 7; case str => yield \"oops\"; };\n"
|
||||
" return 0;\n"
|
||||
"};\n",
|
||||
0, 0 },
|
||||
|
||||
/* match-yield control — same-family arm yields (untyped_int + i32) must
|
||||
* NOT over-reject (the untyped->concrete promotion cstage admits) → run 9. */
|
||||
{ "match_same_yield_ok",
|
||||
"package main;\n"
|
||||
"fn pick(b: bool) (i32 | str) = { if (b) { return 4; }; return \"x\"; };\n"
|
||||
"export fn main() i32 = {\n"
|
||||
" let v: (i32 | str) = pick(true);\n"
|
||||
" let r: i32 = match (v) { case i32 => yield 9; case let s: str => yield 5; };\n"
|
||||
" return r;\n"
|
||||
"};\n",
|
||||
1, 9 },
|
||||
};
|
||||
|
||||
static int
|
||||
run_build(const char *driver, const struct row *r, int i)
|
||||
{
|
||||
char src[64], tmpdir[64], cmd[1024];
|
||||
snprintf(src, sizeof src, "/tmp/f2r_%d_%d.ww", getpid(), i);
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/f2r_%d_d_%d", getpid(), i);
|
||||
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (!f) return -2;
|
||||
fputs(r->src, f);
|
||||
fclose(f);
|
||||
|
||||
mkdir(tmpdir, 0755);
|
||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
||||
tmpdir, driver, src);
|
||||
int brc = runwait(cmd);
|
||||
|
||||
const char *base = strrchr(src, '/');
|
||||
base = base ? base + 1 : src;
|
||||
char outbin[128];
|
||||
snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base);
|
||||
char *dot = strrchr(outbin, '.');
|
||||
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
||||
|
||||
int got = -1;
|
||||
if (brc == 0) got = runwait(outbin);
|
||||
|
||||
unlink(src); unlink(outbin); rmdir(tmpdir);
|
||||
return brc == 0 ? got : -1;
|
||||
}
|
||||
|
||||
static int
|
||||
build_should_fail(const char *driver, const char *src, int i)
|
||||
{
|
||||
char s[64], tmpdir[64], cmd[1024];
|
||||
snprintf(s, sizeof s, "/tmp/f2n_%d_%d.ww", getpid(), i);
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/f2n_%d_d_%d", getpid(), i);
|
||||
|
||||
FILE *f = fopen(s, "wb");
|
||||
if (!f) return -1;
|
||||
fputs(src, f);
|
||||
fclose(f);
|
||||
|
||||
mkdir(tmpdir, 0755);
|
||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
||||
tmpdir, driver, s);
|
||||
int rc = runwait(cmd);
|
||||
|
||||
unlink(s);
|
||||
const char *base = strrchr(s, '/');
|
||||
base = base ? base + 1 : s;
|
||||
char outbin[128];
|
||||
snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base);
|
||||
char *dot = strrchr(outbin, '.');
|
||||
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
||||
unlink(outbin);
|
||||
rmdir(tmpdir);
|
||||
return rc == 0 ? -1 : 0; /* build must NOT succeed */
|
||||
}
|
||||
|
||||
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 cdrv[1024], wdrv[1024];
|
||||
snprintf(cdrv, sizeof cdrv, "%s/ww", bin);
|
||||
snprintf(wdrv, sizeof wdrv, "%s/ww_ww", bin);
|
||||
|
||||
struct { const char *name; const char *drv; int gated; }
|
||||
drivers[] = {
|
||||
{ "cstage", cdrv, 0 },
|
||||
{ "wwstage", wdrv, 1 },
|
||||
{ NULL, NULL, 0 },
|
||||
};
|
||||
|
||||
int n = (int)(sizeof rows / sizeof rows[0]);
|
||||
int total = 0, fail = 0;
|
||||
|
||||
for (int d = 0; drivers[d].name; d++) {
|
||||
if (drivers[d].gated && access(drivers[d].drv, X_OK) != 0) {
|
||||
fprintf(stderr, "catA_f2_reject: skip %s (no %s)\n",
|
||||
drivers[d].name, drivers[d].drv);
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < n; i++) {
|
||||
total++;
|
||||
if (rows[i].expect_build) {
|
||||
int got = run_build(drivers[d].drv, &rows[i], i);
|
||||
if (got != rows[i].want_exit) {
|
||||
fprintf(stderr, "catA_f2_reject[%s][%s]: "
|
||||
"exit=%d want=%d\n", drivers[d].name,
|
||||
rows[i].label, got, rows[i].want_exit);
|
||||
fail++;
|
||||
}
|
||||
} else {
|
||||
if (build_should_fail(drivers[d].drv, rows[i].src,
|
||||
100 + i) != 0) {
|
||||
fprintf(stderr, "catA_f2_reject[%s][%s]: "
|
||||
"built ok, expected a loud reject\n",
|
||||
drivers[d].name, rows[i].label);
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fail) {
|
||||
fprintf(stderr, "catA_f2_reject: %d/%d fixtures failed\n",
|
||||
fail, total);
|
||||
return 1;
|
||||
}
|
||||
printf("catA_f2_reject: %d/%d ok\n", total, total);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user