Fix match in if-then-else branches expanding to vertical with fit-or-vertical (#2798)
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 8056fa50 ("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.
5ebeb8
-
Apr 25 17:25 +00:00