wcc/ww: def-dim array .len field-reads resolve the dimension from the type table

buf.len on a [MAX]u8 returned 0 — the cgdot len arms (local/global/
def) and letemitsize only read an N_INTLIT dimension. Route a
non-literal dimension through tichase().alen (the #21 fix mirrored
into the field-read consumers; .ptr arms are dim-independent).
Review-era task #56.
This commit is contained in:
2026-06-13 01:52:42 +09:00
parent faf1a2908b
commit b97be7301f
6 changed files with 308 additions and 30 deletions

View File

@@ -3444,8 +3444,19 @@ fn cgdot(c: *cgen, n: *node) void = {
if (streq(fld, "len")) {
let lenn: *node = tn.rhs;
let alen: i64 = 0i64;
if (lenn != nil) {
if (lenn.kind == nkind.N_INTLIT) { alen = lenn.uval: i64; };
if (lenn != nil && lenn.kind == nkind.N_INTLIT) {
alen = lenn.uval: i64;
} else {
// #56: def/const dim — resolve from the
// stamped array tinfo (rule-13), the field-
// read twin of the #21 cgslice fix. The dim
// node is an N_IDENT(def), not N_INTLIT, so
// the literal read above defaults 0; cstage
// reads the resolved bu->alen.
let abt: *tinfo = tichase(tn.type_: *tinfo);
if (abt != nil && abt.kind == tykind.TY_ARRAY) {
alen = abt.alen: i64;
};
};
emitline("\tMOVQ\t$");
emitint(alen);
@@ -3679,9 +3690,15 @@ fn cgdot(c: *cgen, n: *node) void = {
if (streq(fld, "len")) {
let lenn: *node = gtn.rhs;
let alen: i64 = 0i64;
if (lenn != nil) {
if (lenn.kind == nkind.N_INTLIT) {
alen = lenn.uval: i64;
if (lenn != nil && lenn.kind == nkind.N_INTLIT) {
alen = lenn.uval: i64;
} else {
// #56: def/const dim on a let-global array —
// resolve from the stamped array tinfo
// (rule-13), twin of the local arm above.
let abt: *tinfo = tichase(gtn.type_: *tinfo);
if (abt != nil && abt.kind == tykind.TY_ARRAY) {
alen = abt.alen: i64;
};
};
emitline("\tMOVQ\t$");
@@ -3723,9 +3740,15 @@ fn cgdot(c: *cgen, n: *node) void = {
if (dtn.kind == nkind.N_TARRAY) {
let lenn: *node = dtn.rhs;
let alen: i64 = 0i64;
if (lenn != nil) {
if (lenn.kind == nkind.N_INTLIT) {
alen = lenn.uval: i64;
if (lenn != nil && lenn.kind == nkind.N_INTLIT) {
alen = lenn.uval: i64;
} else {
// #56: def/const dim on a def array —
// resolve from the stamped array tinfo
// (rule-13), twin of the let-global arm above.
let abt: *tinfo = tichase(dtn.type_: *tinfo);
if (abt != nil && abt.kind == tykind.TY_ARRAY) {
alen = abt.alen: i64;
};
};
emitline("\tMOVQ\t$");