diff --git a/selfhost/cmd/w6c/main.combined.ww b/selfhost/cmd/w6c/main.combined.ww index c82f079a..d80022b2 100644 --- a/selfhost/cmd/w6c/main.combined.ww +++ b/selfhost/cmd/w6c/main.combined.ww @@ -9465,11 +9465,22 @@ fn errnotassign(c: *checker, dst: *node, src: *node, where: str) void = { fn checkletassign(c: *checker, n: *node) void = { if (n == nil) { return; }; - if (n.lhs == nil) { return; }; // no declared type, nothing to check if (n.rhs == nil) { return; }; // no init // hint = nil for A.6.0; A.6.1 will pass n.lhs once STRUCTLIT/ARRLIT // arms consume it. Plumbing-only at this point. let src: *node = exprtype(c, n.rhs, nil); + // Inferred binding (`let r = expr;`, no type annotation). Mirror + // cstage cmd/wcc/check.c:1477 clet `if (t == NULL && initt) t = + // type_default(initt);` and ref/harec/src/check.c:1422 + // check_expr_binding. wwstage carries the let's type on decl.lhs + // (exprtype N_IDENT at L1546 reads s.decl.lhs); cstage carries it + // on Sym.type — same observable result, rule-10 byte-id holds. + // Defaulting (untyped_int → i32, etc.) is exprtype's job at use + // sites, not the binding site. + if (n.lhs == nil) { + if (src != nil) { n.lhs = src; }; + return; + }; if (src == nil) { return; }; // can't infer // #45: alloc([], n) defers element type to the let-init context // (Hare-style). exprtype's alloc-slice branch synthesizes diff --git a/selfhost/cmd/wcc/check.ww b/selfhost/cmd/wcc/check.ww index 5dd6085f..efd7f631 100644 --- a/selfhost/cmd/wcc/check.ww +++ b/selfhost/cmd/wcc/check.ww @@ -2501,11 +2501,22 @@ fn errnotassign(c: *checker, dst: *node, src: *node, where: str) void = { fn checkletassign(c: *checker, n: *node) void = { if (n == nil) { return; }; - if (n.lhs == nil) { return; }; // no declared type, nothing to check if (n.rhs == nil) { return; }; // no init // hint = nil for A.6.0; A.6.1 will pass n.lhs once STRUCTLIT/ARRLIT // arms consume it. Plumbing-only at this point. let src: *node = exprtype(c, n.rhs, nil); + // Inferred binding (`let r = expr;`, no type annotation). Mirror + // cstage cmd/wcc/check.c:1477 clet `if (t == NULL && initt) t = + // type_default(initt);` and ref/harec/src/check.c:1422 + // check_expr_binding. wwstage carries the let's type on decl.lhs + // (exprtype N_IDENT at L1546 reads s.decl.lhs); cstage carries it + // on Sym.type — same observable result, rule-10 byte-id holds. + // Defaulting (untyped_int → i32, etc.) is exprtype's job at use + // sites, not the binding site. + if (n.lhs == nil) { + if (src != nil) { n.lhs = src; }; + return; + }; if (src == nil) { return; }; // can't infer // #45: alloc([], n) defers element type to the let-init context // (Hare-style). exprtype's alloc-slice branch synthesizes diff --git a/selfhost/cmd/wwdump/main.combined.ww b/selfhost/cmd/wwdump/main.combined.ww index 62e5c2b1..356f8d80 100644 --- a/selfhost/cmd/wwdump/main.combined.ww +++ b/selfhost/cmd/wwdump/main.combined.ww @@ -9465,11 +9465,22 @@ fn errnotassign(c: *checker, dst: *node, src: *node, where: str) void = { fn checkletassign(c: *checker, n: *node) void = { if (n == nil) { return; }; - if (n.lhs == nil) { return; }; // no declared type, nothing to check if (n.rhs == nil) { return; }; // no init // hint = nil for A.6.0; A.6.1 will pass n.lhs once STRUCTLIT/ARRLIT // arms consume it. Plumbing-only at this point. let src: *node = exprtype(c, n.rhs, nil); + // Inferred binding (`let r = expr;`, no type annotation). Mirror + // cstage cmd/wcc/check.c:1477 clet `if (t == NULL && initt) t = + // type_default(initt);` and ref/harec/src/check.c:1422 + // check_expr_binding. wwstage carries the let's type on decl.lhs + // (exprtype N_IDENT at L1546 reads s.decl.lhs); cstage carries it + // on Sym.type — same observable result, rule-10 byte-id holds. + // Defaulting (untyped_int → i32, etc.) is exprtype's job at use + // sites, not the binding site. + if (n.lhs == nil) { + if (src != nil) { n.lhs = src; }; + return; + }; if (src == nil) { return; }; // can't infer // #45: alloc([], n) defers element type to the let-init context // (Hare-style). exprtype's alloc-slice branch synthesizes