Semantic Diff

#8906 Keep line comments in operands followed by a block

1 commit, rendered from its record.

Summary

RangeCommitsChangelogAreasJS output changesFormatsFailed checks
5c58e38f86e478f3c0aba128dfcd25250cd91558..pr-89061๐Ÿ› Bug fixprintertests0none0

Changelog draft

๐Ÿ› Bug fix
  • Fix the formatter moving a line comment in the operand of switch, try, if, while or a loop into the block that follows, which changed it again on every format.

5c58e38f86e478f3c0aba128dfcd25250cd91558..pr-8906

1ebd43e18 ยท Christoph Knittel ยท Oct 18, 2026

Keep line comments in operands followed by a block

๐Ÿ› Bug fixprintertests

A line comment inside the operand of switch, try, if, while or a loop was printed as a line suffix in a flat group, so it moved behind the opening brace, and the next format attached it to the block. The operand now breaks the groups around such a comment, and a comment trailing the whole operand goes into parentheses with it, as if conditions already did.

Before ReScript
let x = switch [a, b] { // c| _ => 1}
After ReScript
let x = switch [  a, // c  b,] {| _ => 1}
๐Ÿ› Bug fixFix the formatter moving a line comment in the operand of switch, try, if, while or a loop into the block that follows, which changed it again on every format.

Review

No effect
Output: unchangedFormats: nonePPX: unchangedEditor: unchanged
Formatting
changedoperands of switch, try, if, while and loops that contain a line comment; 80 operand/comment combinations format idempotently (48 did not before), and 330 spread contexts format as before apart from those
Tests
syntax tests/syntax_tests/data/+ printer/comments/operandBeforeBlock.res
6 files ยท +235 โˆ’27 ยท changelog 1 ยท syntax 3 ยท tests 2
Achanges/operand-line-comments.fix.md+1โˆ’0
Mcompiler/syntax/src/res_doc.ml+29โˆ’0
Mcompiler/syntax/src/res_doc.mli+11โˆ’0
Mcompiler/syntax/src/res_printer.ml+50โˆ’27
Atests/syntax_tests/data/printer/comments/expected/operandBeforeBlock.res.txt+92โˆ’0
Atests/syntax_tests/data/printer/comments/operandBeforeBlock.res+52โˆ’0
with Claude Opus 5.5