wcc/check: #150 inferred-type module-global Sym repoint (cstage, #18)

Every inferred-type module-global -- let n = 5; ... return n, or
let g = pt{...}; g.a -- yielded <nil> downstream in cstage: the module
N_LET pass-2 stamped d->type from the initializer but never repointed the
Sym, so later references resolved the still-unstamped Sym. The wwstage
checker already repointed correctly, so this aligns cstage UP (cstage-only;
no combined.ww / check.ww change, w6c_ww unchanged).

Mirrors the #11 [_]-array repoint. The fix is shape-agnostic (keyed on the
unstamped Sym, not the use site) -- verified across scalar/field/arg/index/
str/match/nested inferred-global shapes. Commit B of #150 (Commit A 5c37648
fixed the by-value struct-arg cgen). A pure inferred ARRAY global is now
correct in cstage but trips wwstage asserttyped -- opposite-stage, filed
#125-class. byte-id 990-997 8/8. test/wcc/823 table-driven.
This commit is contained in:
2026-06-08 21:07:47 +09:00
parent 5c3764828f
commit ebd5b8014c
3 changed files with 256 additions and 1 deletions

View File

@@ -3015,7 +3015,19 @@ check_file(Checker *c, Node *file)
err(c, d->pos, "[_]T needs an "
"array-literal initialiser");
}
if (d->type == NULL) d->type = type_default(rt);
if (d->type == NULL) {
d->type = type_default(rt);
/* #150 bug-1: pass-1 installed the Sym with
* the annotation-less NULL type; without
* repointing it, every downstream N_IDENT
* read of this inferred module-global
* resolves nil (`g.a`/`take(g)` → <nil>).
* The general-inferred twin of the #11
* [_]-array Sym repoint above. */
Sym *s = scope_lookup_local(c->cur,
d->str);
if (s) s->type = d->type;
}
if (d->type && rt != ty_err && d->type != ty_err
&& !type_assignable(d->type, rt)
&& !arrlit_init_fits(c, d->type, d->rhs))