wcc,ww: prepend synth use test; user fn run coexists with runner (M4 E2, #80)
The -T harness synthesized `use test;` after name-binding, so the lib/test runner run keyed the bare scope and collided with a user-defined bare fn run — a spurious "duplicate fn run" reject (the E1 tolerance seam). Prepending the synth use before binding keys the runner as test.run in the test module namespace, distinct from the user bare run; the two coexist. Hare-faithful: the runner is its own test module (ref/hare/test/+test.ha:97). Inverts attest_userrun.ww from the #23-mandated reject to a coexist fixture; gate asserts exactly 1 TEXT run + 1 TEXT test.run on the -T asm (distinct symbols, not a dead-dup). Closes #80.
This commit is contained in:
@@ -2856,6 +2856,24 @@ check_file(Checker *c, Node *file)
|
||||
if (file == NULL || file->kind != N_FILE) return;
|
||||
c->file = file;
|
||||
|
||||
/* #80: under -T, PREPEND the synth `use test;` BEFORE pass 1 so decl_mod
|
||||
* (called per-decl during install) sees a matching `use test` when it
|
||||
* keys lib/test's `run` — keying it under module="test", not "". A pure
|
||||
* ORDER fix: the synth N_USE was appended AFTER install (below), too late
|
||||
* for decl_mod, so `run` keyed under "" — leaving the synth `test.run`
|
||||
* ty_err (the E1 bridge) and colliding with a user root `fn run` (also
|
||||
* module=""). Decoupled from cgen: the symbol mangle keys off d->module
|
||||
* (the //ww:module directive, mod_collect), NOT this scope keying — cgen
|
||||
* already emits the correct CALL test.run. wwstage twin in check.ww. */
|
||||
if (c->is_test) {
|
||||
Node *usenode = newnode(c->a, N_USE, file->pos);
|
||||
usenode->str = "test";
|
||||
usenode->strlen = 4;
|
||||
usenode->usepath = "test";
|
||||
usenode->next = file->list;
|
||||
file->list = usenode;
|
||||
}
|
||||
|
||||
/* pass 1: install names (types first, then defs/fns).
|
||||
* For self-referential types we install the named-type placeholder
|
||||
* BEFORE resolving its body; the body may legitimately mention
|
||||
@@ -3196,19 +3214,12 @@ check_file(Checker *c, Node *file)
|
||||
Node *ret = newnode(c->a, N_RETURN, fp);
|
||||
ret->lhs = call;
|
||||
body->list = ret;
|
||||
/* synth `use test;` so the N_DOT base ident binds as a
|
||||
* module qualifier (SK_USE) and use_path maps `test` to
|
||||
* its import path. Mirror the typedecl-pass N_USE install
|
||||
* (check.c:2892). Appended to file->list below; emits no
|
||||
* asm (cgen keys off module-tagged decls). */
|
||||
Node *usenode = newnode(c->a, N_USE, fp);
|
||||
usenode->str = "test";
|
||||
usenode->strlen = 4;
|
||||
usenode->usepath = "test";
|
||||
scope_define(c->cur, "test", SK_USE, NULL, usenode);
|
||||
Node *ul = file->list;
|
||||
if (ul == NULL) file->list = usenode;
|
||||
else { while (ul->next) ul = ul->next; ul->next = usenode; }
|
||||
/* #80: the synth `use test;` (the N_DOT base qualifier +
|
||||
* the use_path source mapping `test`→its path) is now
|
||||
* PREPENDED before pass 1 at the top of check_file, so
|
||||
* decl_mod keys lib/test's `run` under "test" and the synth
|
||||
* `test.run` type-resolves. Pass 1's N_USE arm installs it
|
||||
* (SK_USE). */
|
||||
}
|
||||
|
||||
Node *m = newnode(c->a, N_FNDECL, fp);
|
||||
|
||||
Reference in New Issue
Block a user