Skip to content

fix(parser): refuse a stray = after a do block's last statement - #1889

Merged
nicolas-abril merged 4 commits into
bendlang:mainfrom
nicolas-abril:fix/do-let-stray-eq
Oct 27, 2026
Merged

nicolas-abril merged 4 commits into
bendlang:mainfrom
nicolas-abril:fix/do-let-stray-eq

Conversation

@nicolas-abril

@nicolas-abril nicolas-abril commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1868. Supersedes #1870, whose commit is kept here as the first commit (by @adeerkhan).

What

Inside a do block, a statement the parser can't continue is taken as the block's last term, and the parser returns without checking what follows. With x = v, the leftover = v leaked to the term around the block, which then failed with expected : 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) or return e = v still leaked. This PR replaces that guard with parse_do_end, which runs where the block ends (after return e and after a plain last term) and refuses any = that isn't == or =>:

- expected : a do-block let with its type (write "x : T = ...")
- observed : '='
Location:
12 |     IO.print("a")
13>|     x = pure_of()
   |       ^
14 |     IO.print("ok")

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 a do block in either is already broken. So refusing = can't misfire.

Checks

🤖 Generated with Claude Code

adeerkhan and others added 2 commits October 26, 2026 23:41
…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]>
nicolas-abril and others added 2 commits October 27, 2026 18:04
@nicolas-abril
nicolas-abril merged commit 9a4dfe3 into bendlang:main Oct 27, 2026
1 check passed
@nicolas-abril
nicolas-abril deleted the fix/do-let-stray-eq branch October 27, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Diagnostics: a pure let inside a do block is refused with "expected: a pattern (a binder or a constructor)" pointing at the previous statement

2 participants