lib/ww/parse: error on unknown top-level decl in parsefile fallback (#55)

parsefile's recovery fallback chewed an unrecognized top-level
construct to the next ';' without emitting an error or bumping p.errs,
so a typo'd keyword / stray token silently vanished from the AST and
the build succeeded rc=0 with the declared work gone — no link error
catches a dropped @test or unreferenced exported fn. The C twin
(parse.c:1395-1400) errorf+p->errs++ and rejects. Emit errmsg in the
fallback arm; wwstage now rejects in lockstep with cstage.

lib/ww embeds into the w6c/wwdump combined.ww snapshots; both regen'd.
989_unknowndecl_reject pins the reject-matrix on both driver twins.
This commit is contained in:
2026-06-13 10:33:48 +09:00
parent cf0789c897
commit 5cab22ecec
5 changed files with 231 additions and 0 deletions

View File

@@ -9035,6 +9035,11 @@ export fn parsefile(p: *parser) *node = {
} else { if (p.curkind == tkind.TK_FN) {
d = parsefn(p, exported, attrs);
} else {
// cstage parse.c:1395-1400 errorf+p->errs++ on the
// default arm: an unknown top-level construct is a loud
// reject, not a silent skip. ww chews the whole decl at
// once (below), so one error per fallback entry.
errmsg(p, "expected top-level decl");
// Recovery: chew tokens until next ';' or EOF, balancing
// '{' '}' pairs so internal ';'s in unfamiliar forms don't
// derail us.