cmd+selfhost+test: relax alloc-slice element-type pin via LHS retype
`alloc([], n)` synthesizes ([]u8 | nomem) at expression level — that's fine, since the slice form only legitimately appears in let-init position where the LHS carries the real element type. In clet, after type-checking the rhs, peel any N_TRYPROP/N_TRYUNW wrapper, match the alloc-slice AST shape with the same-module shadow gate (from #23), and retype the call's tagged return to ([]T | nomem) where T is the declared LHS element. Then assignability sees []T vs []T and accepts. Cgen N_LET shortcut gains a viatryprop arm next to the existing viatryunw — on rt_alloc returning null, emits the tagged-return nomem propagation (MOVQ $nidx, AX; epilogue) instead of exit(1). nidx comes from cg_tag_for_variant on the enclosing fn's return type, matching the existing TRYPROP propret path. Wwstage mirrors all four hunks (check.ww + cgenstmt.ww). Promotes the previously-silent conf=false skip into a confident accept. Unblocks #6 (dupall) and lays the path for #4/#7. Byte-identity holds modulo the pre-existing #44 alloc/rt_alloc symbol divergence.
This commit is contained in:
@@ -144,6 +144,20 @@ static const struct row rows[] = {
|
||||
" let s: []u8 = alloc([], 16)!;\n"
|
||||
"};\n",
|
||||
NULL },
|
||||
/* #45: alloc([], n) defers element type to LHS context — `[]str`
|
||||
* with `!` must be accepted (cstage clet retypes, wwstage
|
||||
* checkletassign mirror). Pre-#45 this errored with
|
||||
* "init []u8 not assignable to declared []str" on cstage. */
|
||||
{ "fn caller() void = {\n"
|
||||
" let s: []str = alloc([], 4)!;\n"
|
||||
"};\n",
|
||||
NULL },
|
||||
/* #45: same idiom in `?` form inside a (T | nomem) fn. */
|
||||
{ "fn caller() (i32 | nomem) = {\n"
|
||||
" let s: []str = alloc([], 4)?;\n"
|
||||
" return s.cap: i32;\n"
|
||||
"};\n",
|
||||
NULL },
|
||||
};
|
||||
|
||||
int
|
||||
|
||||
Reference in New Issue
Block a user