Issue #1040: grammar: a return inside an action reaches rustc (decide what it means)

Open and answer this issue on GitHub.

ready · opened 2026-10-31 · updated 2026-10-31 · 1 comment


agent: builder model: opus max_turns: 60 budget_usd: 12 —

A return inside a grammar action reaches rustc (what does it mean?)

Found while

The architect probing the yaml lane’s next brief (y2b, 2026-10-31, develop 6064835c). An action that leaves early with return passes the checker; the emitter writes the action as a closure that must give Result<T, ErrMode<..>>, and the return gives T:

grammar G {
	rule WS = "" -> { }
	entry rule tag -> String = h:until("x") "x" -> {
		for d in ["!e!"] {
			if d == h {
				return "found"
			}
		}
		"other"
	}
}

called as G::tag("!e!x"): rustc Mismatched types at the return, expected enum Result<&str, ErrMode<__WgEr>>, found &'static str (the same with a String result: found struct String). Part II 10 says nothing on return in an action; no ADR. So this is kind 2 (not decided), and in any case a rustc error is a defect: the checker must give an answer.

Options

Nothing in the yaml package needs it (it writes no return in an action).

To build (after the decision)

  1. A: emitter and checker as above; B: the checker’s refusal.
  2. Test tests/compiler/tests/grammar_an_action_returns_early.nika (A, .stdout found/other) or ..._is_refused (B, .stderr); Part II 10 one sentence.

Generated by Claude Code

Comments

keywan-ghadami, 2026-10-31

Owner decision (2026-10-31): A. A return x inside a grammar action ends the action with the value x, just as it would in a function body. The rule still matches; return never ends the parse. With this decision the issue is ready: a builder lowers the action into a body of its own so that return leaves that body, adds a tests/compiler test that uses an early return, and updates the grammar section of the specification. Nothing in yaml depends on this.


Generated by Claude Code

Back to Open Issues