Fix match in if-then-else branches expanding to vertical with fit-or-vertical#2798
Merged
Conversation
…vertical
When a `match expr with` appeared as a branch of `if-then-else` with
`if-then-else=fit-or-vertical`, the match keyword, scrutinee, and
`with` were broken onto separate lines even when they easily fit on one
line:
if true then
match
expr
with
| true -> ()
| false -> ()
The regression was introduced by 8056fa5 ("Overhaul begin match
formatting"), which changed `fmt_match` to wrap `pro` inside a nested
`hvbox 0 (pro_inner $ keyword)`. When the match is inside an
if-then-else branch, the `pro` carries a `break_unless_newline 1000 2`
(from the Fit_or_vertical branch_pro). This inflates the inner hvbox's
size to 1000+, causing the Format engine to classify the parent hovbox
as non-fitting, which forces all breaks in the `match .. expr .. with`
box to break.
Fix: in `match_inner_pro`, return `false` for `Pexp_ifthenelse` context
(same as already done for `Pexp_infix`), so that `pro` is placed
outside the match's inner hvbox as `pro_outer`, where it does not
interfere with the match keyword/expr/with fitting on one line.
Julow
approved these changes
Apr 23, 2026
Collaborator
Julow
left a comment
There was a problem hiding this comment.
That's the right fix, thanks !
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.
When a
match expr withappeared as a branch ofif-then-elsewithif-then-else=fit-or-vertical, the match keyword, scrutinee, andwithwere broken onto separate lines even when they easily fit on one line:The regression was introduced by 8056fa5 ("Overhaul begin match formatting"), which changed
fmt_matchto wrapproinside a nestedhvbox 0 (pro_inner $ keyword). When the match is inside an if-then-else branch, theprocarries abreak_unless_newline 1000 2(from the Fit_or_vertical branch_pro). This inflates the inner hvbox's size to 1000+, causing the Format engine to classify the parent hovbox as non-fitting, which forces all breaks in thematch .. expr .. withbox to break.Fix: in
match_inner_pro, returnfalseforPexp_ifthenelsecontext (same as already done forPexp_infix), so thatprois placed outside the match's inner hvbox aspro_outer, where it does not interfere with the match keyword/expr/with fitting on one line.Fix #2766. This fix was vibe-clauded.