Repository navigation
Description
Summary
Add tests proving local bindings and explicit imports shadow prelude names deterministically. The behavior appears implemented and partially covered, but the requirements campaign wants direct coverage for §18.2's name-precedence claims.
Spec
§18.2 says local bindings and explicit use imports win over prelude names, and defining print in a module makes calls to print(...) resolve to the local definition (docs/with-specification.md:9575-9577). The prelude is injected before user source (src/compiler/Frontend.w:976-1005), so user declarations must override or be selected over ambient imports.
Current state
Prelude injection is explicit in Zcu.inject_prelude_frontend and parse_with_prelude_first_mode (src/compiler/Frontend.w:977-1005). Existing files such as test/behavior/prelude_shadow_local.w, test/behavior/prelude_shadow_explicit.w, and helper modules indicate some coverage exists, but the requirements campaign recorded 18.2.1.13 and 18.2.1.14 as missing direct tests in this campaign slice (out/req-campaign/g13.tsv:13-14). The original survey also verified local fn print wins.
Implementation plan
- Audit existing prelude shadow tests and avoid duplicating equivalent assertions. If they already cover both requirements directly, update requirement trace comments in the test body.
- Add or strengthen a local-shadow test where a local
fn printor local binding named like a prelude function wins overstd.builtins.print. - Add explicit-import precedence coverage: import a helper module exporting a name that also exists in the prelude and assert the imported version is called.
- Ensure tests are deterministic and do not depend on import order beyond the spec rule.
Test plan
Add or update test/behavior/prelude_shadow_local.w:
- define a local
fn print(s: str)that records/returns a value instead of writing stdout. - call
print("x")and assert the local function ran.
Add or update test/behavior/prelude_shadow_explicit.w:
- helper module exports a prelude-colliding name.
- explicit
use helpercauses calls to resolve to helper, not prelude.
Add a --no-prelude sanity file only if needed to separate ordinary unknown-name errors from shadowing behavior.
Acceptance criteria
- §18.2 local-over-prelude precedence is directly asserted.
- §18.2 explicit-import-over-prelude precedence is directly asserted.
- Existing prelude injection behavior is not changed.
with build && with build :fixpoint && with build :testpass.
Dependencies
None.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 18.2.1.13, 18.2.1.14.
Activity
ehartford commentedon Jul 3, 2026
Closing as COVERED: local prelude shadowing (prelude_shadow_local: local fn map/filter/sum win) and explicit-import shadowing (prelude_shadow_explicit: use shadow_helper wins) both assert 18.2.1.13/14 on HEAD. §18.