Skip to content

bugfix: fix cases parsing in doc eval block#6137

Merged
mitchellwrosen merged 3 commits intotrunkfrom
26-01-22-cases-in-doc
Jan 26, 2026
Merged

bugfix: fix cases parsing in doc eval block#6137
mitchellwrosen merged 3 commits intotrunkfrom
26-01-22-cases-in-doc

Conversation

@mitchellwrosen
Copy link
Member

@mitchellwrosen mitchellwrosen commented Jan 23, 2026

Overview

Fixes #5983

This PR fixes the issue where docs would fail to parse with a terrible empty error message when they contained an eval block that ended with a cases, such as

x.doc = {{
  ```
  cases x -> 1
  ```
}}

(or just try editing all @unison/cloud docs for many more realistic examples in the wild).

It took a bit to track down, but the issue is that we need to generate a random name for the variable binding, when desugaring to a lambda, for which we use a unique name generator that is a function of next token's position in the file. If there are no more tokens in the file, it fails. (Tokens in an eval block are lex'd separately, so we hit EOF at the end of each one).

I fixed this by simply allowing unique name generation at the end of a file, by using the dummy position Pos (-1) (-1).

Test coverage

I added a regression test

@mitchellwrosen mitchellwrosen marked this pull request as ready for review January 23, 2026 18:11
Copy link
Contributor

@aryairani aryairani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@mitchellwrosen mitchellwrosen merged commit 9b79ca1 into trunk Jan 26, 2026
31 checks passed
@mitchellwrosen mitchellwrosen deleted the 26-01-22-cases-in-doc branch January 26, 2026 18:41
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.

cases block needs surrounding parens in Doc only

2 participants