Skip to content

Tests: prelude shadowing coverage (§18) #519

Closed

Description

@ehartford

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

  1. 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.
  2. Add or strengthen a local-shadow test where a local fn print or local binding named like a prelude function wins over std.builtins.print.
  3. 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.
  4. 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 helper causes 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 :test pass.

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

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions