selfhost/cmd/wcc/check+test: reject bare alloc(v) at let-init in wwstage

Cstage's check.c:981-1006/1052-1082 builds a real (*T|nomem) /
([]T|nomem) return type for the alloc builtin; wwstage was returning
nil from exprtype's N_CALL arm (alloc is SK_FN with decl=nil under
seedprimitives), and checkletassign early-returned on nil src,
silently accepting `let p: *T = alloc(v);` without `!`. Stage
asymmetry that #30 papered over until now.

Three coordinated edits in check.ww:
- exprtype N_CALL: synthesize N_TTAGGED{N_TPTR{argt}, nomem} or
  {N_TSLICE{u8}, nomem} for bare alloc (same-module gated, mirrors
  cstage check.c:981-985 / task #23).
- exprtype N_TRYUNW: project the success variant so `let p:*T =
  alloc(v)!;` resolves rhs to *T.
- isassignable: tagged → non-tagged is unconditionally not
  assignable, forcing match/?/!.

950_selfcheck.c rows pin both ptr and slice forms.
This commit is contained in:
2026-05-20 00:03:43 +09:00
parent dd27ce3339
commit 6f10c832a4
4 changed files with 240 additions and 0 deletions

View File

@@ -120,6 +120,30 @@ static const struct row rows[] = {
" return \"hi\";\n"
"};\n",
"return: not assignable" },
/* #31: alloc(value) returns (*T | nomem); bare LHS without `!`
* must be rejected — pre-fix, exprtype returned the seeded
* builtin's nil lhs and checkletassign silently passed. */
{ "fn caller() void = {\n"
" let p: *u8 = alloc(0u8: u8);\n"
"};\n",
"let: not assignable" },
/* #31: with `!` the unwrap projects the *u8 success variant,
* so the let must be accepted. */
{ "fn caller() void = {\n"
" let p: *u8 = alloc(0u8: u8)!;\n"
"};\n",
NULL },
/* #31: slice form `alloc([], n)` returns ([]u8 | nomem); the
* tagged → non-tagged rule must also fire for the bare LHS. */
{ "fn caller() void = {\n"
" let s: []u8 = alloc([], 16);\n"
"};\n",
"let: not assignable" },
/* #31: with `!` the slice success variant projects to []u8. */
{ "fn caller() void = {\n"
" let s: []u8 = alloc([], 16)!;\n"
"};\n",
NULL },
};
int