Skip to content

t27c: optional capture dropped, orelse unparsed, test-local reassign emitted as const, pointer param var rename #6358

Description

@gHashTag

Found by the t27b optionals lane (#6357), Refs #6063. Each is a t27c (parser or gen-zig) defect that makes the reference path refuse a well-formed spec:

  1. if (x) |v| { ... } -- gen-zig drops the |v| capture; zig then reports v as undeclared. t27b refuses the shape as StmtIf(capture).
  2. orelse does not parse in t27c.
  3. In a test block, a plain assignment w = 9; to a name already declared with var is emitted as const w = 9;, a redeclaration zig rejects.
  4. A mutated pointer parameter is renamed to var p = p_arg;, which zig rejects as "never mutated" when only p.* is written.

For 3 and 4, t27b currently passes such files while the reference does not compile them; they sit outside the 720 reference passes, so no count changes, but t27b should refuse them by name until the reference is fixed.

Boundary

  • bootstrap/src/compiler.rs

User Scenarios

  • Given a spec with if (x) |v| { use(v); }, when compiled by t27c, then the generated Zig must declare the capture v so the Zig compiler accepts it.
  • Given a spec containing orelse in an optional chain, when parsed by t27c, then the parser must accept the keyword and produce a valid AST node.
  • Given a test block where var w = 1; is followed by w = 9;, when codegen runs, then the reassignment must be emitted as a variable assignment, not a const redeclaration.
  • Given a function taking a pointer parameter p: *i32 that mutates p.*, when codegen renames the parameter, then the generated Zig must not emit var p = p_arg; if only p.* is written.

Requirements

  • FR-001: The gen-zig backend MUST emit a capture variable for optional if patterns so the Zig compiler sees the declared name.
  • FR-002: The parser MUST recognize orelse as a valid keyword in optional expressions and produce a corresponding AST node.
  • FR-003: In test blocks, assignments to already-declared var names MUST be emitted as mutable assignments, not const redeclarations.
  • FR-004: When a pointer parameter is only mutated through dereference (p.*), the codegen MUST NOT emit a var p = p_arg; shadow that Zig flags as never mutated.

Success Criteria

  • cargo test -p t27c -- optional_capture exits 0 and the generated Zig for if (x) |v| {} compiles without "undeclared identifier" errors.
  • cargo test -p t27c -- orelse_parse exits 0 and a spec containing orelse parses without syntax errors.
  • cargo test -p t27c -- test_reassign_const exits 0 and the emitted Zig for w = 9; inside a test block compiles without "redeclaration" errors.
  • cargo test -p t27c -- ptr_param_rename exits 0 and the emitted Zig for a mutated pointer parameter compiles without "never mutated" errors.
  • All 720 reference specs in specs/tools/tri/test.t27 still pass (t27c exit 0).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions