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.
Overview
Empty code blocks still fail, but as a normal Unison error, not a Haskell exception. This matches their behavior in previous releases.
Fixes #5349.
Implementation notes
With the update to the Doc2 parser in #5187, there was the introduction of a dummy layout block used to delimit the boundary of the Unison parser state outside the current Doc2 block and inside it.
There were two bugs here – the first was using
List.last
, which is what crashed the lexer when there were no tokens lexed. That is avoided by always getting a fresh position rather than the position of the last token.But that hid the real issue, which is that if there were no tokens lexed, the dummy block never moved to layout and rather than inserting the correct number of
Close
tokens to complete the block, it closed all of the blocks, including the ones outside of the Doc2 block. Since theParsingEnv
islocal
, we can just start with an emptylayout
, making it impossible to close extra blocks.Test coverage
There is a new transcript that covers a few different code blocks in Doc cases, and a trivial empty lex case in unison-syntax tests.
Loose ends
There is still some overly complicated layout-based logic spread throughout the lexer, notably in
token''
.Empty blocks still fail, which matches the previous behavior, but we should handle this more gracefully inside Doc, so that bad Docs don’t fail the parser.