diff --git a/selfhost/cmd/w6c/main.combined.ww b/selfhost/cmd/w6c/main.combined.ww index 9b4b8b04..abe37332 100644 --- a/selfhost/cmd/w6c/main.combined.ww +++ b/selfhost/cmd/w6c/main.combined.ww @@ -8699,6 +8699,35 @@ fn exprtype(c: *checker, e: *node, hint: *node) *node = { }; return nil; }; + if (k == nkind.N_STRUCTLIT) { + // A.6.1.6 — head-only stamp of the struct-lit's overall type. + // Mirror cstage cmd/wcc/check.c:1161-1197; field-level walk + // (cstage L1178-1194) parked behind #23 / Phase 2 — field + // values are walked by the post-order exprtype dispatch at + // L460-489, so each field expr still gets its own n.type_. + // + // Parser at lib/ww/parse/expr.ww:147-148 always plants the + // TYPE_IDENT in e.lhs; e.lhs == nil would be a future Hare- + // style anonymous struct lit we don't yet parse — bail. + if (e.lhs == nil) { return nil; }; + if (e.lhs.kind == nkind.N_IDENT) { + let ms: *sym = scopelookupprefer(c.cur, c.curmod, e.lhs.str); + if (ms != nil) { if (ms.skind == skind.SK_TYPE) { if (ms.decl != nil) { + let tn: *node = ms.decl.lhs; + if (tn != nil) { + e.type_ = tinfofornode(c, tn): *void; + return tn; + }; + }; }; }; + // Lenient on miss: cstage L1170 errors, wwstage falls + // through (scruttype L656 / A.6.1.5b N_DOT struct-miss). + return nil; + }; + // Synthetic type-expr (`(*T){...}` etc). Mirror cstage L1175 + // resolve_type(c, n->lhs). + e.type_ = tinfofornode(c, e.lhs): *void; + return e.lhs; + }; if (k == nkind.N_TRYPROP) { // success unwrap: the success-variant type of operand's // tagged union. diff --git a/selfhost/cmd/wcc/check.ww b/selfhost/cmd/wcc/check.ww index 85905dc3..16632b52 100644 --- a/selfhost/cmd/wcc/check.ww +++ b/selfhost/cmd/wcc/check.ww @@ -1767,6 +1767,35 @@ fn exprtype(c: *checker, e: *node, hint: *node) *node = { }; return nil; }; + if (k == nkind.N_STRUCTLIT) { + // A.6.1.6 — head-only stamp of the struct-lit's overall type. + // Mirror cstage cmd/wcc/check.c:1161-1197; field-level walk + // (cstage L1178-1194) parked behind #23 / Phase 2 — field + // values are walked by the post-order exprtype dispatch at + // L460-489, so each field expr still gets its own n.type_. + // + // Parser at lib/ww/parse/expr.ww:147-148 always plants the + // TYPE_IDENT in e.lhs; e.lhs == nil would be a future Hare- + // style anonymous struct lit we don't yet parse — bail. + if (e.lhs == nil) { return nil; }; + if (e.lhs.kind == nkind.N_IDENT) { + let ms: *sym = scopelookupprefer(c.cur, c.curmod, e.lhs.str); + if (ms != nil) { if (ms.skind == skind.SK_TYPE) { if (ms.decl != nil) { + let tn: *node = ms.decl.lhs; + if (tn != nil) { + e.type_ = tinfofornode(c, tn): *void; + return tn; + }; + }; }; }; + // Lenient on miss: cstage L1170 errors, wwstage falls + // through (scruttype L656 / A.6.1.5b N_DOT struct-miss). + return nil; + }; + // Synthetic type-expr (`(*T){...}` etc). Mirror cstage L1175 + // resolve_type(c, n->lhs). + e.type_ = tinfofornode(c, e.lhs): *void; + return e.lhs; + }; if (k == nkind.N_TRYPROP) { // success unwrap: the success-variant type of operand's // tagged union. diff --git a/selfhost/cmd/wwdump/main.combined.ww b/selfhost/cmd/wwdump/main.combined.ww index 30d6691d..93db3948 100644 --- a/selfhost/cmd/wwdump/main.combined.ww +++ b/selfhost/cmd/wwdump/main.combined.ww @@ -8699,6 +8699,35 @@ fn exprtype(c: *checker, e: *node, hint: *node) *node = { }; return nil; }; + if (k == nkind.N_STRUCTLIT) { + // A.6.1.6 — head-only stamp of the struct-lit's overall type. + // Mirror cstage cmd/wcc/check.c:1161-1197; field-level walk + // (cstage L1178-1194) parked behind #23 / Phase 2 — field + // values are walked by the post-order exprtype dispatch at + // L460-489, so each field expr still gets its own n.type_. + // + // Parser at lib/ww/parse/expr.ww:147-148 always plants the + // TYPE_IDENT in e.lhs; e.lhs == nil would be a future Hare- + // style anonymous struct lit we don't yet parse — bail. + if (e.lhs == nil) { return nil; }; + if (e.lhs.kind == nkind.N_IDENT) { + let ms: *sym = scopelookupprefer(c.cur, c.curmod, e.lhs.str); + if (ms != nil) { if (ms.skind == skind.SK_TYPE) { if (ms.decl != nil) { + let tn: *node = ms.decl.lhs; + if (tn != nil) { + e.type_ = tinfofornode(c, tn): *void; + return tn; + }; + }; }; }; + // Lenient on miss: cstage L1170 errors, wwstage falls + // through (scruttype L656 / A.6.1.5b N_DOT struct-miss). + return nil; + }; + // Synthetic type-expr (`(*T){...}` etc). Mirror cstage L1175 + // resolve_type(c, n->lhs). + e.type_ = tinfofornode(c, e.lhs): *void; + return e.lhs; + }; if (k == nkind.N_TRYPROP) { // success unwrap: the success-variant type of operand's // tagged union.