fix(scanner): suppress ASI before catch and finally keywords#246
Merged
VladimirMakaev merged 1 commit intomainfrom Mar 4, 2026
Merged
fix(scanner): suppress ASI before catch and finally keywords#246VladimirMakaev merged 1 commit intomainfrom
VladimirMakaev merged 1 commit intomainfrom
Conversation
The scanner was inserting automatic semicolons before `catch` and `finally` keywords on new lines, breaking common Kotlin patterns like multi-catch and try-catch-finally across lines. - Add `catch` and `finally` as continuation keywords in the main ASI switch and line comment inner switch - Add `prec.right` to `try_expression` to resolve the grammar-level ambiguity (dangling-else style) between ending the try expression and continuing with catch/finally - Remove the now-unnecessary `[$.try_expression]` conflict declaration - Add 4 regression tests for try-catch-catch, try-catch-finally, and comment-separated variants
6fd31ad to
c8dd373
Compare
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.
Summary
catchandfinallyas ASI continuation keywords so the scanner does not insert automatic semicolons before them on new linesprec.righttotry_expressionto resolve the dangling-else style grammar ambiguity between ending the try expression and continuing withcatch/finally[$.try_expression]conflict declaration (resolved byprec.right)Fixes common Kotlin patterns that were previously misparsed:
Test plan
try {} catch {} catch {}— both catches intry_expressiontry {} catch {} finally {}—finallyintry_expressiontry {} catch {} // commentthencatch {}— line comment + catchtry {} catch {} // commentthenfinally {}— line comment + finallytry {} finally {}— control case, already worked