Repository navigation
fix(parser): refuse a stray = after a do block's last statement - #1889
Merged
Merged
Conversation
…at the let's line (bendlang#1868) x = v is refused inside a do block with "a pattern (a binder or a constructor)" and the caret on the previous statement, because the leftover = v was re-parsed as the next statement. The typed form (x : T = v, the grammar's DoLet) works; now the refusal says so, where the statement is, and the spec test pins it.
The previous commit caught only `x = v` with a plain-name head; a
destructure (`(a, b) = v`, `Pair{a, b} = v`), a dotted name (`m.k = v`)
or `return e = v` still leaked the `= v` past the block, to surface as
"a pattern" on the statement before it (bendlang#1868). The check now sits where
the block ends (after `return e` and after a plain last term) and fires
on any `=` that is not `==` or `=>`; the caret lands on the `=`.
The do-let pin moves to tests/parse/do_let_untyped.bend, and
check/monad_do_destructure's pin takes the new refusal.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # tests/parse/do_let_untyped.bend
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.
Closes #1868. Supersedes #1870, whose commit is kept here as the first commit (by @adeerkhan).
What
Inside a
doblock, a statement the parser can't continue is taken as the block's last term, and the parser returns without checking what follows. Withx = v, the leftover= vleaked to the term around the block, which then failed withexpected : a pattern (a binder or a constructor)on the statement before the let.#1870 caught this for a plain-name head only. A destructure (
(a, b) = v,Pair{a, b} = v), a dotted name (m.k = v) orreturn e = vstill leaked. This PR replaces that guard withparse_do_end, which runs where the block ends (afterreturn eand after a plain last term) and refuses any=that isn't==or=>:Untyped do-lets are still not accepted; the message points to the typed form.
Why only
=A broader check ("nothing but a dedent or a closer may follow the last statement") refuses valid code: a
)on its own deeper line,x : T = do M: return v;(the outer let takes the;), and{do M: a == b : T}. The only places the parser accepts a bare=after a term are a let's pattern and a typed let's type, and adoblock in either is already broken. So refusing=can't misfire.Checks
.bendfile usingdo(254) run with--check-onlybefore and after: only the pins below changed (re-run after merging main).tests/parse/do_let_untyped_after_step.bend(moved from fix(parser): a do-block let without its type names the working form, at the let's line #1870'stests/spec/comp_do_let.bend, which isn't a comp-splice pin): the refusal above.tests/parse/do_let_untyped.bend(from A do-block bind or let written without its type gets a note on its error #1807): its pin now takes the new refusal. A do-block bind or let written without its type gets a note on its error #1807's note inerr_lost_typeonly fired when the let was a plain name and the error span started at it, which is not the Diagnostics: a pure let inside a do block is refused with "expected: a pattern (a binder or a constructor)" pointing at the previous statement #1868 case; its<-note is unaffected.tests/check/monad_do_destructure.bend: its pin now takes the new refusal on(a, b) = p, not the old error on the line before.bun gates/repo.ts: 54 / 54.gates/test.tsshards (cluster) were not run.🤖 Generated with Claude Code