Skip to content

fix(parser): a do-block let without its type names the working form, at the let's line - #1870

Closed
adeerkhan wants to merge 1 commit into
bendlang:mainfrom
adeerkhan:fix/do-let-untyped
Closed

adeerkhan wants to merge 1 commit into
bendlang:mainfrom
adeerkhan:fix/do-let-untyped

Conversation

@adeerkhan

Copy link
Copy Markdown
Contributor

Closes #1868

What

x = pure_of() inside a do block is refused with expected : a pattern (a binder or a constructor) and the caret on the previous statement (the leftover = v was being re-parsed as the next statement). The typed form the grammar's DoLet takes — x : T = v — works; the refusal now says exactly that, located on the let itself:

- expected : a do-block let with its type (write "x : T = ...", or bind the value before the block)
- observed : 'x '
Location:
15 |     IO.print("a")
16>|     x = pure_of()
   |     ^^
17 |     IO.print("ok")

The guard is four conditions in parse_term_do_stmt, right where a statement term has been parsed: a Var head, no : to follow (that is the typed path), no == (keep the equality statement as it was), and an = waiting — then parse_fail with the message above. Nothing else in the statement parse moved.

Why

The message named neither the rule nor the line: the caret sat on IO.print("a") and the observation showed an IO.bind, so the first suspect was the desugaring, not the let. Full characterization (four spellings) in #1868 with the correction comment: typed lets were always fine.

Checks

  • tests/spec/comp_do_let.bend — new spec pin: the refusal above, the location, exit 1. Run with bun bend2/main.ts tests/spec/comp_do_let.bend: output matches the pin.
  • tests/spec/comp_let_split.bend — still refuses identically (its pin unchanged).
  • The typed-let control (x : Nat = pure_of() then IO.print("ok")) still runs and prints ok.
  • bun gates/repo.ts: bend2/bend.ts under its 48k cap; the one red file (bendtt.lean 64885 > 64000) is pre-existing on main and untouched here.
  • The full gates/test.ts shards need the mini cluster — not run locally; the change is a parse-time refusal on a form that never parsed.

…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.
@nicolas-abril

Copy link
Copy Markdown
Collaborator

Superseded by #1889, which keeps this commit as its first and generalizes the guard: the check now runs where the do block ends and catches any stray = (destructures, dotted names, return e = v), not just a plain-name head. Thanks for the fix and the test — it's moved to tests/parse/do_let_untyped.bend.

nicolas-abril added a commit that referenced this pull request Oct 27, 2026
An untyped do-block let (`x = v`, `(a, b) = v`, `m.k = v`, `return e = v`) leaked its `= v` past the block and surfaced as "a pattern" on the statement before it (#1868). The block's end now refuses any `=` that is not `==` or `=>`, with the caret on the `=`. Supersedes #1870.

Co-authored-by: Adeer Khan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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