Repository navigation
fix(parser): recv-define select arms unparseable in second-or-later position - #1429
Open
lilyliiphone2026-collab wants to merge 1 commit into
Conversation
The arm-body terminator looks_like_select_arm_head recognized send arms (ch <- v:), bare recv arms (<-ch:), and comma-ok recv-define arms (v, ok := <-ch:) — but not the single-name recv-define arm (v := <-ch:). Any select whose second or later arm was a named recv-define therefore died with "expected expression, found ':'": the body loop swallowed the arm head as a local declaration and choked on the trailing colon. While fixing it, the comma-ok branch's final token check turned out to be off by one: after the name walk k lands on ':=', but the check demanded an Ident there — so comma-ok arms in second position failed the same way. Both shapes are now recognized. - add the missing ':=' branch to the single-name lookahead - fix the comma-walk's final check (nth(k) is ':=', not an Ident) - regression test: second_recv_define_select_arm_parses (3 shapes) - corpus program select-two-recv-define-arms-accept.hy (ACCEPT; the pre-fix parser rejected this shape outright) The gap had zero coverage: corpus 24 pairs one named arm with a bare arm, examples use send/default arms only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Any
selectwhose second or later arm was a named recv-define arm failed to parse:Comma-ok arms (
w, ok := <-b:) failed identically in second position.One named arm alone parsed fine, which is why the corpus missed it:
24-shadow-scope-map-reject.hy pairs one named arm with a bare arm, and every example uses send/default arms only.
Root cause (two bugs, same lookahead)
looks_like_select_arm_head— the arm-body terminator insideparse_select— recognized:cur = Ident,nth(1) = "<-"cur = "<-"Identatnth(k)where the walk already landskon":=")and had no branch at all for the single-name recv-define head
Ident ":=" "<-".So the previous arm's body loop swallowed the arm head as a local declaration, hit the trailing colon, and
parse_stmtfailed withexpected expression, found ':'. The arm-kind detector itself (first-iteration path) always handled both shapes correctly — only the terminator lookahead was broken, which is exactly why first arms worked and later arms didn't.Fix
Tok::Punct(":=") => matches!(self.nth(2), Tok::Punct("<-"))branch for single-name recv-define headsnth(k) == ":=" && nth(k+1) == "<-"Verification
second_recv_define_select_arm_parses(three shapes: named+named, comma-ok+comma-ok, named+comma-ok) — passesselect-two-recv-define-arms-accept.hy(ACCEPT, end-to-end: check → emit → go build → run outputs2) — passes with the fix, failed to parse beforecargo test --workspace: all green (173 + 112 parser + rest, 0 failures)tools/differential_loop.py: reject-side 86/86, accept-side 38/40 — the two accept-side disagreements are the pre-existingcgo: gcc not foundWindows-env failures in corpus 12/13, reproduced identically on an unpatched baseline buildBounty
Submitted under the BOUNTY.md Track 2 — useful improvements ladder (2026-11-01 cycle): diagnostic-adjacent tooling fix with regression coverage. The issue-creation guidance in BOUNTY.md covers bugs and wildcards; this is a fix PR, so it goes straight to the ladder per "Improvements: a normal issue or a PR".