lex: clear pending modpath on module-reset, fix empty-module stale-modpath miscompile (#9)

BUG-A #9: when an empty/export-less inlined module body produces `//ww:module <p>` immediately followed by `//ww:module-reset` in one skipws run, lexnext drained TK_MODRESET first then emitted the STALE TK_MODPATH past the reset boundary, re-binding pathmod=<p> so the root `package main` was validated against <p> -> wrong reject. Fix clears the pending modpath at the reset-RECOGNITION site in skipws (NOT lexnext drain): cstage l->modpath=NULL after both l->modreset=1 (cmd/wcc/lex.c); selfhost l.modpathset=0 after all three l.modreset=1 (lib/ww/syntax/lex.ww). Symmetric (rule-10): identical token streams, bootstrap byte-id holds. The normal RESET-then-PATH boundary is unaffected (clear is a no-op when no path is pending). Pin: test/wcc/989_modresetadj_run.c feeds the raw composed adjacency to w6c+w6c_ww (accept + byte-id), red-path-proven (reverting a clear reddens it). A separate wwi-producer defect surfaced (decl-less .wwi defaults to 'package main') filed as #11; not touched here.
This commit is contained in:
2026-06-22 19:49:57 +09:00
parent 99b98b9b1b
commit c0383274d1
4 changed files with 226 additions and 3 deletions

View File

@@ -501,7 +501,8 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \
$(BIN)/test_w6c_ww $(BIN)/test_ww_ww $(BIN)/test_self_rebuild \
$(BIN)/test_dyn_ww $(BIN)/test_selfcheck \
$(BIN)/test_attest_record $(BIN)/test_attest_drop \
$(BIN)/test_declns_sep $(BIN)/test_wwispread_sep \
$(BIN)/test_declns_sep $(BIN)/test_modresetadj_run \
$(BIN)/test_wwispread_sep \
$(BIN)/test_fmt_run $(BIN)/test_log_run $(BIN)/test_fnmatch_run \
$(BIN)/test_shlex_run $(BIN)/test_getenv_run $(BIN)/test_dirs_run \
$(BIN)/test_dirs_toolong_run \
@@ -2657,6 +2658,15 @@ $(BIN)/test_declns_sep: test/wcc/989_declns_sep.c $(BIN)/ww $(BIN)/ww_ww \
$(BIN)/w6l $(BIN)/w6l_ww $(LIB)/libwwrt.a | $(BIN)
$(CC) $(CFLAGS) -o $@ $<
# #9 (BUG-A) — the lexer must clear a pending modpath when a `//ww:module-reset`
# is recognized in the same skipws run (empty/export-less inlined module body).
# Feeds the composed adjacency unit DIRECTLY to w6c/w6c_ww (the driver trips #11
# first), then assembles+links+runs → all four frontend/asm/link tools + libwwrt.
$(BIN)/test_modresetadj_run: test/wcc/989_modresetadj_run.c \
$(BIN)/w6c $(BIN)/w6c_ww $(BIN)/w6a $(BIN)/w6l \
$(LIB)/libwwrt.a | $(BIN)
$(CC) $(CFLAGS) -o $@ $<
# #95 — .wwi producer must preserve the `...` union-spread marker; dir-package
# `ww build --sep` + run, both driver stages, 2-arm + 3-arm shapes + cs==ww.
$(BIN)/test_wwispread_sep: test/wcc/989_wwispread_sep.c $(BIN)/ww $(BIN)/ww_ww \