Skip to content

t27b: a test local named for a module var (StmtLocal(shadows module var)), the rest of #7422 (zig_test_shadowing) #7668

Closed

Description

@gHashTag

Part of #6063 (t27b coverage), which is item C10 of #6488. This is the second half of #7422, split off when the first half landed.

specs/compiler/zig_test_shadowing.t27 passes under t27c test-report (3 tests, 5 runtime asserts). t27b refuses it.

The reference renames such a local to <name>_lv (W736 in fns, #6295 in tests and benches), and the rename applies to every mention of the name in that body. That matches t27 scoping exactly when three things hold:

  • the declaration is a top-level statement of the body;
  • it is the body's only declaration of the name;
  • nothing before it mentions the name, including its own initializer.

In every other case the reference refuses the file (use of undeclared identifier 'g_lv', redeclaration of local variable 'g_lv'), as #7422 recorded.

#7447 implements this in 34 hand-written lines of cli/t27b/src/lower.rs. It is CONFLICTING with master and predates the owner's 2026-10-07 direction that t27b gets no new hand-written Rust features. Under that direction the decision goes into a .t27 plan, t27c gen-rust turns it into a generated file, and lower.rs mounts that file with #[path] (#7614, #7657). The glue that reads the facts off the Node tree is capped at 40 added lines per file and 80 per PR (#7371).

Done when:

  • zig_test_shadowing.t27 passes under t27b test by test, as it does under the reference;
  • a conformance spec covers the three conditions and the refused shapes;
  • the lab's full corpus with the reference shows mismatch 0, reference disagree 0, and nothing leaving pass.

User Scenarios

  • Given a test body declares a local variable with the same name as a module-level var (e.g., var READY: bool = true; where READY is a module variable), when the declaration is a top-level statement of the body, is the body's only declaration of that name, and nothing before it mentions the name including its own initializer, then t27b renames the local to <name>_lv throughout that body and the test passes.
  • Given a test body declares a local that shadows a module variable but violates any of the three conditions (not top-level, multiple declarations of the name, or a prior mention including in its own initializer), then t27b refuses the file with a redeclaration or undeclared identifier error, matching the reference compiler's behavior.
  • Given the spec specs/compiler/zig_test_shadowing.t27 which contains the shadowing pattern, when run under t27b test-report, then all 3 tests and 5 runtime asserts pass exactly as they do under t27c test-report.

Requirements

  • FR-001: The shadow-local renaming logic for module-variable shadowing in tests and benches MUST be expressed in a .t27 plan file, compiled via t27c gen-rust into a generated Rust file, and mounted in cli/t27b/src/lower.rs via #[path].
  • FR-002: The generated logic MUST rename a test/bench local to <name>_lv iff all three conditions hold: (a) declaration is a top-level statement of the body, (b) it is the body's only declaration of that name, (c) nothing before it mentions the name including its own initializer.
  • FR-003: When the three conditions do not all hold, the compiler MUST refuse the file with the same error messages as the reference (use of undeclared identifier 'g_lv' or redeclaration of local variable 'g_lv').
  • FR-004: The hand-written Rust glue in lower.rs that reads facts off the Node tree MUST not exceed 40 added lines in that file and 80 added lines total in the PR.
  • FR-005: A conformance spec MUST cover the three positive conditions and the refused shapes (negative cases).

Success Criteria

  • t27b test-report specs/compiler/zig_test_shadowing.t27 exits with exit 0 and reports 3 tests passed, 5 runtime asserts passed.
  • A conformance spec file (location per implementation) exists and passes under both t27c test-report and t27b test-report, covering the three conditions and refused shapes.
  • Running the lab's full corpus comparison shows mismatch 0, reference disagree 0, and no tests leaving pass status.
  • cli/t27b/src/lower.rs mounts the generated file via #[path] and adds ≤40 lines of glue code.

Boundary

  • specs/compiler/zig_test_shadowing.t27
  • cli/t27b/src/lower.rs
  • specs/tools/tri/test.t27
  • specs/tools/trinity/tri/test.t27
  • scripts/tri_loop/t27b.py

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions