Skip to content

fix(scanner): suppress ASI before catch and finally keywords#246

Merged
VladimirMakaev merged 1 commit intomainfrom
fix/comment-asi-followup
Mar 4, 2026
Merged

fix(scanner): suppress ASI before catch and finally keywords#246
VladimirMakaev merged 1 commit intomainfrom
fix/comment-asi-followup

Conversation

@VladimirMakaev
Copy link
Copy Markdown
Collaborator

@VladimirMakaev VladimirMakaev commented Mar 4, 2026

Summary

  • Add catch and finally as ASI continuation keywords so the scanner does not insert automatic semicolons before them on new lines
  • Add prec.right to try_expression to resolve the dangling-else style grammar ambiguity between ending the try expression and continuing with catch/finally
  • Remove the now-unnecessary [$.try_expression] conflict declaration (resolved by prec.right)

Fixes common Kotlin patterns that were previously misparsed:

try { foo() }
catch (e: Exception) { }   // second catch on new line
catch (e: Error) { }
finally { close() }         // finally on new line

Test plan

  • All 286 tests pass (282 existing + 4 new)
  • try {} catch {} catch {} — both catches in try_expression
  • try {} catch {} finally {}finally in try_expression
  • try {} catch {} // comment then catch {} — line comment + catch
  • try {} catch {} // comment then finally {} — line comment + finally
  • try {} finally {} — control case, already worked
  • Parser size unchanged (229 bytes smaller due to conflict removal)

@github-actions github-actions bot added grammar Related to the grammar scanner Related to the external scanner labels Mar 4, 2026
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
@VladimirMakaev VladimirMakaev force-pushed the fix/comment-asi-followup branch from 6fd31ad to c8dd373 Compare March 4, 2026 12:51
@VladimirMakaev VladimirMakaev marked this pull request as ready for review March 4, 2026 12:55
@VladimirMakaev VladimirMakaev merged commit f3a1ea7 into main Mar 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

grammar Related to the grammar scanner Related to the external scanner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant