wcc: resolve value-receiver field-call type via callee, not global leaf (#208)

wwstage exprtype's N_CALL arm fell into a global-leaf scopelookup for an
N_DOT callee with a value or chained receiver, binding whatever same-named
global headed the scope bucket. Under a late-os combined.ww concat order
this resolved io's `s.read(...)` to os.read (i64) instead of the field's
fn type, so checkretassign confidently rejected a valid tagged return — an
import-order-sensitive false positive. cstage resolves a call result solely
from the callee expr's own type (check.c:1378-1433, mirroring harec
check_autodereference 1566-1581); drop the global-leaf else-arm so value
and chained receivers fall through to the existing fn-VALUE path at
check.ww:2455. SK_USE module-qualified calls are unchanged.

ww has no methods, so `value.leaf()` is only ever a fn-ptr field access; the
global hit was never legitimate. Zero .s delta across all 5 bootstrap tools
(the branch is dead in the bootstrap); test 776 graduates to both stages
(os-late order, byte-identical).

The fix unmasks a pre-existing wwstage cgen bug (#211): cgen also re-derives
a call's return shape by name (fnretlookup), so a value-receiver field call
whose leaf collides with a same-named global of a different register shape
mis-resolves cs!=ww. Documented at the cgen site; pinned cstage-only by
test/wcc/782 (graduates to STAGE_WW on #211 close).
This commit is contained in:
2026-05-29 15:27:50 +09:00
parent bc9d7df002
commit 4e1181fd8c
7 changed files with 317 additions and 33 deletions

View File

@@ -2428,10 +2428,23 @@ fn exprtype(c: *checker, e: *node, hint: *node) *node = {
if (mu != nil) { ms = mu; };
};
};
// #208: only a module-qualified callee (SK_USE receiver)
// resolves its leaf by name here. A value receiver
// (`s.read(...)`, `(*p).read()`, `a.b.read()`) is a
// fn-pointer FIELD call whose result type comes from the
// FIELD's fn type, not a global-leaf lookup. The old
// `scopelookup(c.cur, nm)` else-arm bound whichever
// same-leaf global fn headed the flat scope bucket —
// order-sensitive (os.read:i64 vs io.read:(i32|eof|closed)
// flipped by combined.ww concat order), yielding a
// false `return: not assignable`. Leaving s nil falls
// through to the fn-VALUE path below (exprtype(callee) →
// TPTR peel → TFN.ret), matching cstage cmd/wcc/check.c
// :1378-1433 (call result IS the callee type's ret; no
// global-leaf path) and harec check_autodereference
// (ref/harec/src/check.c:1566-1581).
if (ms != nil && ms.skind == skind.SK_USE) {
s = scopelookupinmodule(c.cur, callee.lhs.str, nm);
} else {
s = scopelookup(c.cur, nm);
};
};
if (s != nil) { if (s.skind == skind.SK_FN) { if (s.decl != nil) {