Fix vertical breaks in let-in with comments before 'in'#2813
Open
yakobowski wants to merge 2 commits into
Open
Fix vertical breaks in let-in with comments before 'in'#2813yakobowski wants to merge 2 commits into
yakobowski wants to merge 2 commits into
Conversation
This was referenced Jul 4, 2026
Add test cases to let_binding.ml covering: - Short comment after value that fits on one line (currently broken across lines regardless of configuration) - Function body with trailing comment (same issue) - Long expression with comment that legitimately needs a break The bug affects all profiles/configurations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
`let x = value (* comment *) in` was being broken across multiple lines regardless of configuration because comments near the `in` keyword were formatted with `force_break` as their prefix, which unconditionally forced the containing hvbox to vertical mode. Fix: change `~pro:force_break` to `~pro:(break 1 0)` in two places in fmt_value_binding — the comment is now a regular break that becomes a space when the hvbox fits horizontally. When the content exceeds the margin, the box still goes vertical naturally. This also fixes a non-idempotency: previously, `let x = v (* c *) in` and its pre-broken equivalent produced different outputs. The bug affects all profiles (default, ocamlformat, janestreet, ahrefs). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
|
#2810 is uniformly better on the if-then-else issue, so I'm dropping those commits from the MR. |
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.
I'm currently migrating a big codebase which is formatted using ocamlformat 0.22. I have noticed quite a few improvements (thanks!) but also some regressions. Some of them are fixed by #2810. The remaining ones are related to comments in a let binding.
Bug:
let x = value (* comment *) in bodyis always broken across multiple lines, even when it fits within the margin. Theforce_breakprefix on comments nearinunconditionally forced the containing hvbox to vertical mode.Fix:
~pro:force_break → ~pro:(break 1 0)in two places in fmt_value_binding. The comment now gets a regular break (becomes a space when the box fits horizontally, still breaks when it doesn't). Also fixes a non-idempotency where the one-liner and its pre-broken form produced different outputs. Affects all profiles.