From 47367a029453e73f2db0b5ba8fbdf7d29b04f598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Wed, 24 Jun 2026 08:15:49 +0200 Subject: [PATCH 1/7] Params: deduplicate branch_pro_with_cmts across if-then-else modes The `Compact` and `Fit_or_vertical` arms of `get_if_then_else` each carried a near-identical block computing `branch_pro` for the case of a comment preceding a special branch body, and their inline break expressions (`break 1000 0 $ cmts $ break 1000 0` and `break 1000 2 $ cmts`) duplicated exactly what `raw_cmts_branch_pro` already computes per mode. Extract a single `branch_pro_with_cmts ~default ~guard` helper that reuses `raw_cmts_branch_pro`, parameterized by each mode's comment-less `branch_pro` and its extra applicability guard. Behavior is unchanged (the full test suite passes with no ref changes). Co-Authored-By: Claude Opus 4.8 (1M context) --- lib/Params.ml | 72 +++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/lib/Params.ml b/lib/Params.ml index 155f82c562..4f72cd4497 100644 --- a/lib/Params.ml +++ b/lib/Params.ml @@ -929,31 +929,40 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~pro ~first ~last | None when parens_bch -> str " " | None -> break 1 indent in + (* When a comment precedes a multi-line + [match]/[function]/[try]/[if-then-else] branch body (or a [begin]/[end] + wrapping one), emit it from [branch_pro] with forced breaks, so the + branch indentation stays stable regardless of where the comment was + initially attached. [default] is the comment-less [branch_pro] for the + current mode, [guard] an extra mode-specific applicability condition. *) + let branch_pro_with_cmts ~default ~guard = + if + (not has_beginend) + && (not (Location.is_single_line expr_loc c.fmt_opts.margin.v)) + && (not has_cmts_after_kw) && guard + then + match cmts_before_opt xbch.ast.pexp_loc with + | Some cmts -> raw_cmts_branch_pro c cmts + | None -> ( + match xbch.ast.pexp_desc with + | Pexp_beginend ({pexp_loc; pexp_desc; _}, _) + when is_special_beginend pexp_desc -> ( + match cmts_before_opt pexp_loc with + | Some cmts -> raw_cmts_branch_pro c cmts + | None -> default ) + | _ -> default ) + else default + in match c.fmt_opts.if_then_else.v with | `Compact -> - let branch_pro_with_cmts = - if - (not has_beginend) && (not parens_bch) - && (not (Location.is_single_line expr_loc c.fmt_opts.margin.v)) - && (not has_cmts_after_kw) - && is_special_or_nested_special_beginend xbch.ast.pexp_desc - then - match cmts_before_opt xbch.ast.pexp_loc with - | Some cmts -> break 1000 0 $ cmts $ break 1000 0 - | None -> ( - match xbch.ast.pexp_desc with - | Pexp_beginend ({pexp_loc; pexp_desc; _}, _) - when is_special_beginend pexp_desc -> ( - match cmts_before_opt pexp_loc with - | Some cmts -> break 1000 0 $ cmts $ break 1000 0 - | None -> branch_pro ~indent:0 () ) - | _ -> branch_pro ~indent:0 () ) - else branch_pro ~indent:0 () - in { box_branch= hovbox ~name:"Params.get_if_then_else `Compact" 2 ; cond= cond () ; box_keyword_and_expr= Fn.id - ; branch_pro= branch_pro_with_cmts + ; branch_pro= + branch_pro_with_cmts ~default:(branch_pro ~indent:0 ()) + ~guard: + ( (not parens_bch) + && is_special_or_nested_special_beginend xbch.ast.pexp_desc ) ; wrap_parens= wrap_parens ~wrap_breaks: @@ -982,24 +991,6 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~pro ~first ~last ; space_between_branches= fmt_if (has_beginend || parens_bch) (str " ") } | `Fit_or_vertical -> - let branch_pro_with_cmts = - if - (not has_beginend) - && (not (Location.is_single_line expr_loc c.fmt_opts.margin.v)) - && not has_cmts_after_kw - then - match cmts_before_opt xbch.ast.pexp_loc with - | Some cmts -> break 1000 2 $ cmts - | None -> ( - match xbch.ast.pexp_desc with - | Pexp_beginend ({pexp_loc; pexp_desc; _}, _) - when is_special_beginend pexp_desc -> ( - match cmts_before_opt pexp_loc with - | Some cmts -> break 1000 2 $ cmts - | None -> branch_pro ~begin_end_offset:0 () ) - | _ -> branch_pro ~begin_end_offset:0 () ) - else branch_pro ~begin_end_offset:0 () - in { box_branch= hovbox ( match imd with @@ -1007,7 +998,10 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~pro ~first ~last | _ -> 0 ) ; cond= cond () ; box_keyword_and_expr= Fn.id - ; branch_pro= branch_pro_with_cmts + ; branch_pro= + branch_pro_with_cmts + ~default:(branch_pro ~begin_end_offset:0 ()) + ~guard:true ; wrap_parens= wrap_parens ~wrap_breaks: From 199bd389e2db2021eac2eb95f48e2415ff79a2a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Wed, 24 Jun 2026 10:27:26 +0200 Subject: [PATCH 2/7] Fix indentation of bare match branch after comment with fit-or-vertical MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With `if-then-else=fit-or-vertical`, an `if … else (* cmt *) match … with` branch (a bare match/function/try/if, not wrapped in begin/end or parentheses) rendered the branch body indented to the comment's end column instead of under the comment. `Params.raw_cmts_branch_pro` emitted, for non-Compact modes, `break 1000 2 $ cmts` with no trailing break. A bare branch's body breaks with `break_unless_newline`, a no-op unless already at the beginning of a line, and `fmt_match` opens its box at the current column — the comment's end column. Add an optional `~bare_branch` flag that appends a trailing break so the body box opens at the line start. It is not set for begin/end- or paren-wrapped branches, which emit their opening delimiter right after the comment, keeping that rendering unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) --- CHANGES.md | 5 +++++ lib/Fmt_ast.ml | 7 ++++++- lib/Params.ml | 20 ++++++++++++++++--- lib/Params.mli | 12 +++++++++-- test/passing/refs.ahrefs/ite-compact.ml.ref | 10 ++++++++++ .../refs.ahrefs/ite-compact_closing.ml.ref | 11 ++++++++++ .../refs.ahrefs/ite-fit_or_vertical.ml.ref | 11 ++++++++++ .../ite-fit_or_vertical_closing.ml.ref | 12 +++++++++++ .../ite-fit_or_vertical_no_indicate.ml.ref | 11 ++++++++++ test/passing/refs.ahrefs/ite-kr.ml.ref | 12 +++++++++++ .../passing/refs.ahrefs/ite-kr_closing.ml.ref | 12 +++++++++++ test/passing/refs.ahrefs/ite-kw_first.ml.ref | 11 ++++++++++ .../refs.ahrefs/ite-kw_first_closing.ml.ref | 12 +++++++++++ .../ite-kw_first_no_indicate.ml.ref | 11 ++++++++++ .../refs.ahrefs/ite-no_indicate.ml.ref | 10 ++++++++++ test/passing/refs.ahrefs/ite-vertical.ml.ref | 11 ++++++++++ test/passing/refs.ahrefs/ite.ml.ref | 10 ++++++++++ test/passing/refs.default/ite-compact.ml.ref | 8 ++++++++ .../refs.default/ite-compact_closing.ml.ref | 8 ++++++++ .../refs.default/ite-fit_or_vertical.ml.ref | 15 ++++++++++++-- .../ite-fit_or_vertical_closing.ml.ref | 15 ++++++++++++-- .../ite-fit_or_vertical_no_indicate.ml.ref | 15 ++++++++++++-- test/passing/refs.default/ite-kr.ml.ref | 8 ++++++++ .../refs.default/ite-kr_closing.ml.ref | 8 ++++++++ test/passing/refs.default/ite-kw_first.ml.ref | 11 ++++++++++ .../refs.default/ite-kw_first_closing.ml.ref | 11 ++++++++++ .../ite-kw_first_no_indicate.ml.ref | 11 ++++++++++ .../refs.default/ite-no_indicate.ml.ref | 8 ++++++++ test/passing/refs.default/ite-vertical.ml.ref | 11 ++++++++++ test/passing/refs.default/ite.ml.ref | 8 ++++++++ .../refs.janestreet/ite-compact.ml.ref | 11 ++++++++++ .../ite-compact_closing.ml.ref | 12 +++++++++++ .../ite-fit_or_vertical.ml.ref | 12 +++++++++++ .../ite-fit_or_vertical_closing.ml.ref | 13 ++++++++++++ .../ite-fit_or_vertical_no_indicate.ml.ref | 12 +++++++++++ test/passing/refs.janestreet/ite-kr.ml.ref | 13 ++++++++++++ .../refs.janestreet/ite-kr_closing.ml.ref | 13 ++++++++++++ .../refs.janestreet/ite-kw_first.ml.ref | 12 +++++++++++ .../ite-kw_first_closing.ml.ref | 13 ++++++++++++ .../ite-kw_first_no_indicate.ml.ref | 12 +++++++++++ .../refs.janestreet/ite-no_indicate.ml.ref | 11 ++++++++++ .../refs.janestreet/ite-vertical.ml.ref | 12 +++++++++++ test/passing/refs.janestreet/ite.ml.ref | 11 ++++++++++ .../refs.ocamlformat/ite-compact.ml.ref | 8 ++++++++ .../ite-compact_closing.ml.ref | 8 ++++++++ .../ite-fit_or_vertical.ml.ref | 19 +++++++++++++++--- .../ite-fit_or_vertical_closing.ml.ref | 19 +++++++++++++++--- .../ite-fit_or_vertical_no_indicate.ml.ref | 19 +++++++++++++++--- test/passing/refs.ocamlformat/ite-kr.ml.ref | 8 ++++++++ .../refs.ocamlformat/ite-kr_closing.ml.ref | 8 ++++++++ .../refs.ocamlformat/ite-kw_first.ml.ref | 13 ++++++++++++ .../ite-kw_first_closing.ml.ref | 13 ++++++++++++ .../ite-kw_first_no_indicate.ml.ref | 13 ++++++++++++ .../refs.ocamlformat/ite-no_indicate.ml.ref | 8 ++++++++ .../refs.ocamlformat/ite-vertical.ml.ref | 13 ++++++++++++ test/passing/refs.ocamlformat/ite.ml.ref | 8 ++++++++ test/passing/tests/ite.ml | 10 ++++++++++ 57 files changed, 628 insertions(+), 21 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 67dcb7faac..b72c1fcfd1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,11 @@ profile. This started with version 0.26.0. ### Fixed +- Fix indentation of a bare `match`/`function`/`try` branch preceded by a + comment with `if-then-else=fit-or-vertical`: the branch is no longer + indented relative to the comment's end column. + (#2810, @MisterDA) + - Fix formatting oscillation with `if-then-else=fit-or-vertical` and `begin...end`. (#2800, @MisterDA) diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index a136f24f34..a4c8cb21db 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -2593,7 +2593,12 @@ and fmt_expression c ?(box = true) ?(pro = noop) ?eol ?parens let branch_pro = match raw_cmts_after_kw with | Some cmts -> - Params.raw_cmts_branch_pro c.conf cmts + let bare_branch = + Params.is_bare_branch ~parens_bch + xbch.ast.pexp_desc + in + Params.raw_cmts_branch_pro ~bare_branch c.conf + cmts | None -> p.branch_pro in let wrap_beginend = diff --git a/lib/Params.ml b/lib/Params.ml index 4f72cd4497..c3800d43a9 100644 --- a/lib/Params.ml +++ b/lib/Params.ml @@ -516,9 +516,22 @@ let is_special_or_nested_special_beginend = function | Pexp_beginend ({pexp_desc; _}, _) -> is_special_beginend pexp_desc | exp -> is_special_beginend exp -let raw_cmts_branch_pro (c : Conf.t) cmts = +(* An if-then-else branch is rendered "bare" when it is neither wrapped in + [begin]/[end] (including the [begin match end] shortcut, a + [Pexp_beginend]) nor parenthesized. *) +let is_bare_branch ~parens_bch desc = + (not parens_bch) && match desc with Pexp_beginend _ -> false | _ -> true + +let raw_cmts_branch_pro ?(bare_branch = false) (c : Conf.t) cmts = match c.fmt_opts.if_then_else.v with | `Compact -> break 1000 0 $ cmts $ break 1000 0 + (* A bare [match]/[function]/[try]/[if] branch breaks before its own body + with a [break_unless_newline], which is a no-op unless we are already at + the beginning of a line; without a trailing break here the branch box + would open at the comment's end column and indent the body relative to + it. A [begin]/[end]- or paren-wrapped branch instead emits its opening + delimiter right after the comment, so we leave the break to it. *) + | _ when bare_branch -> break 1000 2 $ cmts $ break 1000 2 | _ -> break 1000 2 $ cmts type cases = @@ -878,6 +891,7 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~pro ~first ~last | _ -> (None, None, xbch) in let has_beginend = Option.is_some beginend_loc in + let bare_branch = is_bare_branch ~parens_bch xbch.ast.pexp_desc in let wrap_parens ~wrap_breaks k = if has_beginend then let infix_ext_attrs_beginend = @@ -942,13 +956,13 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~pro ~first ~last && (not has_cmts_after_kw) && guard then match cmts_before_opt xbch.ast.pexp_loc with - | Some cmts -> raw_cmts_branch_pro c cmts + | Some cmts -> raw_cmts_branch_pro ~bare_branch c cmts | None -> ( match xbch.ast.pexp_desc with | Pexp_beginend ({pexp_loc; pexp_desc; _}, _) when is_special_beginend pexp_desc -> ( match cmts_before_opt pexp_loc with - | Some cmts -> raw_cmts_branch_pro c cmts + | Some cmts -> raw_cmts_branch_pro ~bare_branch c cmts | None -> default ) | _ -> default ) else default diff --git a/lib/Params.mli b/lib/Params.mli index 776ba51399..c1c5531d22 100644 --- a/lib/Params.mli +++ b/lib/Params.mli @@ -242,10 +242,18 @@ val is_special_or_nested_special_beginend : expression_desc -> bool the keyword should be extracted without breaks (raw) to prevent oscillation between "after keyword" and "before expression" placements. *) -val raw_cmts_branch_pro : Conf.t -> Fmt.t -> Fmt.t +val is_bare_branch : parens_bch:bool -> expression_desc -> bool +(** [is_bare_branch ~parens_bch desc] is whether an if-then-else branch with + expression description [desc] is rendered "bare", i.e. neither wrapped in + [begin]/[end] (including the [begin match end] shortcut) nor parenthesized. *) + +val raw_cmts_branch_pro : ?bare_branch:bool -> Conf.t -> Fmt.t -> Fmt.t (** [raw_cmts_branch_pro c cmts] returns the branch_pro for raw comments extracted after a keyword, using the correct indentation for the current - if-then-else mode. *) + if-then-else mode. [bare_branch] (default [false]) indicates the branch is + a bare [match]/[function]/[try]/[if] (not wrapped in [begin]/[end] or + parentheses); such a branch needs a forced break after the comment so that + its body is not indented relative to the comment's end column. *) val match_indent : ?default:int -> Conf.t -> parens:bool -> ctx:Ast.t -> int (** [match_indent c ~ctx ~default] returns the indentation used for the diff --git a/test/passing/refs.ahrefs/ite-compact.ml.ref b/test/passing/refs.ahrefs/ite-compact.ml.ref index 62816583fb..5cecf62364 100644 --- a/test/passing/refs.ahrefs/ite-compact.ml.ref +++ b/test/passing/refs.ahrefs/ite-compact.ml.ref @@ -230,3 +230,13 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) diff --git a/test/passing/refs.ahrefs/ite-compact_closing.ml.ref b/test/passing/refs.ahrefs/ite-compact_closing.ml.ref index 5325ce7382..afecf296ca 100644 --- a/test/passing/refs.ahrefs/ite-compact_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-compact_closing.ml.ref @@ -250,3 +250,14 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b + ) diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref index f6dbbe1bc9..588060ddaa 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref @@ -273,3 +273,14 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *)( + match e with + | A -> a + | B -> b) diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref index 568bde8b61..dda0cc0440 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref @@ -284,3 +284,15 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *)( + match e with + | A -> a + | B -> b + ) diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref index f6dbbe1bc9..588060ddaa 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref @@ -273,3 +273,14 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *)( + match e with + | A -> a + | B -> b) diff --git a/test/passing/refs.ahrefs/ite-kr.ml.ref b/test/passing/refs.ahrefs/ite-kr.ml.ref index 40be4b4384..073ec2f740 100644 --- a/test/passing/refs.ahrefs/ite-kr.ml.ref +++ b/test/passing/refs.ahrefs/ite-kr.ml.ref @@ -310,3 +310,15 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else ( + (* a comment *) + match e with + | A -> a + | B -> b + ) diff --git a/test/passing/refs.ahrefs/ite-kr_closing.ml.ref b/test/passing/refs.ahrefs/ite-kr_closing.ml.ref index fdf791c892..7162d363d9 100644 --- a/test/passing/refs.ahrefs/ite-kr_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-kr_closing.ml.ref @@ -317,3 +317,15 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else ( + (* a comment *) + match e with + | A -> a + | B -> b + ) diff --git a/test/passing/refs.ahrefs/ite-kw_first.ml.ref b/test/passing/refs.ahrefs/ite-kw_first.ml.ref index 0dd5acf1bc..572b9ec54d 100644 --- a/test/passing/refs.ahrefs/ite-kw_first.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first.ml.ref @@ -265,3 +265,14 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) diff --git a/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref b/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref index e0b9284f1d..90ba78b33e 100644 --- a/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref @@ -285,3 +285,15 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b + ) diff --git a/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref index 0dd5acf1bc..572b9ec54d 100644 --- a/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref @@ -265,3 +265,14 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) diff --git a/test/passing/refs.ahrefs/ite-no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-no_indicate.ml.ref index 62816583fb..5cecf62364 100644 --- a/test/passing/refs.ahrefs/ite-no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-no_indicate.ml.ref @@ -230,3 +230,13 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) diff --git a/test/passing/refs.ahrefs/ite-vertical.ml.ref b/test/passing/refs.ahrefs/ite-vertical.ml.ref index 6d41adb8e8..57f3f40112 100644 --- a/test/passing/refs.ahrefs/ite-vertical.ml.ref +++ b/test/passing/refs.ahrefs/ite-vertical.ml.ref @@ -310,3 +310,14 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) diff --git a/test/passing/refs.ahrefs/ite.ml.ref b/test/passing/refs.ahrefs/ite.ml.ref index 62816583fb..5cecf62364 100644 --- a/test/passing/refs.ahrefs/ite.ml.ref +++ b/test/passing/refs.ahrefs/ite.ml.ref @@ -230,3 +230,13 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) diff --git a/test/passing/refs.default/ite-compact.ml.ref b/test/passing/refs.default/ite-compact.ml.ref index 3672c44671..2bb4a004b3 100644 --- a/test/passing/refs.default/ite-compact.ml.ref +++ b/test/passing/refs.default/ite-compact.ml.ref @@ -223,3 +223,11 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with A -> a | B -> b diff --git a/test/passing/refs.default/ite-compact_closing.ml.ref b/test/passing/refs.default/ite-compact_closing.ml.ref index 8fc1245502..a738e1750c 100644 --- a/test/passing/refs.default/ite-compact_closing.ml.ref +++ b/test/passing/refs.default/ite-compact_closing.ml.ref @@ -238,3 +238,11 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with A -> a | B -> b diff --git a/test/passing/refs.default/ite-fit_or_vertical.ml.ref b/test/passing/refs.default/ite-fit_or_vertical.ml.ref index 4214040eeb..6823b0ea2b 100644 --- a/test/passing/refs.default/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical.ml.ref @@ -259,8 +259,8 @@ let _ = b else (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - match x with - | A -> f + match x with + | A -> f (* Comment before nested if in then branch - Compact mode oscillation *) let _ = @@ -273,3 +273,14 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + match e with + | A -> a + | B -> b diff --git a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref index 64810afbfe..2d41da0941 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref @@ -268,8 +268,8 @@ let _ = b else (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - match x with - | A -> f + match x with + | A -> f (* Comment before nested if in then branch - Compact mode oscillation *) let _ = @@ -282,3 +282,14 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + match e with + | A -> a + | B -> b diff --git a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref index 4214040eeb..6823b0ea2b 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref @@ -259,8 +259,8 @@ let _ = b else (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - match x with - | A -> f + match x with + | A -> f (* Comment before nested if in then branch - Compact mode oscillation *) let _ = @@ -273,3 +273,14 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + match e with + | A -> a + | B -> b diff --git a/test/passing/refs.default/ite-kr.ml.ref b/test/passing/refs.default/ite-kr.ml.ref index 0773c03e16..18e5097328 100644 --- a/test/passing/refs.default/ite-kr.ml.ref +++ b/test/passing/refs.default/ite-kr.ml.ref @@ -306,3 +306,11 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) match e with A -> a | B -> b diff --git a/test/passing/refs.default/ite-kr_closing.ml.ref b/test/passing/refs.default/ite-kr_closing.ml.ref index d16ca01a77..5a25615277 100644 --- a/test/passing/refs.default/ite-kr_closing.ml.ref +++ b/test/passing/refs.default/ite-kr_closing.ml.ref @@ -313,3 +313,11 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) match e with A -> a | B -> b diff --git a/test/passing/refs.default/ite-kw_first.ml.ref b/test/passing/refs.default/ite-kw_first.ml.ref index a0941721b7..2ed516f897 100644 --- a/test/passing/refs.default/ite-kw_first.ml.ref +++ b/test/passing/refs.default/ite-kw_first.ml.ref @@ -259,3 +259,14 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else + (* a comment *) + match e with + | A -> a + | B -> b diff --git a/test/passing/refs.default/ite-kw_first_closing.ml.ref b/test/passing/refs.default/ite-kw_first_closing.ml.ref index 546b602f91..e1aa0f329d 100644 --- a/test/passing/refs.default/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.default/ite-kw_first_closing.ml.ref @@ -274,3 +274,14 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else + (* a comment *) + match e with + | A -> a + | B -> b diff --git a/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref index a0941721b7..2ed516f897 100644 --- a/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref @@ -259,3 +259,14 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else + (* a comment *) + match e with + | A -> a + | B -> b diff --git a/test/passing/refs.default/ite-no_indicate.ml.ref b/test/passing/refs.default/ite-no_indicate.ml.ref index 3672c44671..2bb4a004b3 100644 --- a/test/passing/refs.default/ite-no_indicate.ml.ref +++ b/test/passing/refs.default/ite-no_indicate.ml.ref @@ -223,3 +223,11 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with A -> a | B -> b diff --git a/test/passing/refs.default/ite-vertical.ml.ref b/test/passing/refs.default/ite-vertical.ml.ref index 04eb6fbb61..5c7eb37b9f 100644 --- a/test/passing/refs.default/ite-vertical.ml.ref +++ b/test/passing/refs.default/ite-vertical.ml.ref @@ -312,3 +312,14 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + match e with + | A -> a + | B -> b diff --git a/test/passing/refs.default/ite.ml.ref b/test/passing/refs.default/ite.ml.ref index 3672c44671..2bb4a004b3 100644 --- a/test/passing/refs.default/ite.ml.ref +++ b/test/passing/refs.default/ite.ml.ref @@ -223,3 +223,11 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with A -> a | B -> b diff --git a/test/passing/refs.janestreet/ite-compact.ml.ref b/test/passing/refs.janestreet/ite-compact.ml.ref index 02d22ac756..c9203b2905 100644 --- a/test/passing/refs.janestreet/ite-compact.ml.ref +++ b/test/passing/refs.janestreet/ite-compact.ml.ref @@ -235,3 +235,14 @@ let _ = else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-compact_closing.ml.ref b/test/passing/refs.janestreet/ite-compact_closing.ml.ref index e98406e08f..ea57aa99c5 100644 --- a/test/passing/refs.janestreet/ite-compact_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-compact_closing.ml.ref @@ -250,3 +250,15 @@ let _ = else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref index 35c0fdedf6..d2bd3bd125 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref @@ -288,3 +288,15 @@ let _ = else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *)( + match e with + | A -> a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref index 97b3d2aca5..4ff166ae94 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref @@ -300,3 +300,16 @@ let _ = else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *)( + match e with + | A -> a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref index 35c0fdedf6..d2bd3bd125 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref @@ -288,3 +288,15 @@ let _ = else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *)( + match e with + | A -> a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-kr.ml.ref b/test/passing/refs.janestreet/ite-kr.ml.ref index 20a2ed5f27..29b1c8a72e 100644 --- a/test/passing/refs.janestreet/ite-kr.ml.ref +++ b/test/passing/refs.janestreet/ite-kr.ml.ref @@ -336,3 +336,16 @@ let _ = else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else ( + (* a comment *) + match e with + | A -> a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-kr_closing.ml.ref b/test/passing/refs.janestreet/ite-kr_closing.ml.ref index 0bcf83e649..8f916d8755 100644 --- a/test/passing/refs.janestreet/ite-kr_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-kr_closing.ml.ref @@ -343,3 +343,16 @@ let _ = else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else ( + (* a comment *) + match e with + | A -> a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-kw_first.ml.ref b/test/passing/refs.janestreet/ite-kw_first.ml.ref index 2b16944d25..7eccbbf131 100644 --- a/test/passing/refs.janestreet/ite-kw_first.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first.ml.ref @@ -269,3 +269,15 @@ let _ = else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref b/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref index 3111239793..0b2eea44e3 100644 --- a/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref @@ -284,3 +284,16 @@ let _ = else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref index 2b16944d25..7eccbbf131 100644 --- a/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref @@ -269,3 +269,15 @@ let _ = else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-no_indicate.ml.ref b/test/passing/refs.janestreet/ite-no_indicate.ml.ref index 02d22ac756..c9203b2905 100644 --- a/test/passing/refs.janestreet/ite-no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-no_indicate.ml.ref @@ -235,3 +235,14 @@ let _ = else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-vertical.ml.ref b/test/passing/refs.janestreet/ite-vertical.ml.ref index d99e8aad56..ca83aeaa78 100644 --- a/test/passing/refs.janestreet/ite-vertical.ml.ref +++ b/test/passing/refs.janestreet/ite-vertical.ml.ref @@ -333,3 +333,15 @@ let _ = else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite.ml.ref b/test/passing/refs.janestreet/ite.ml.ref index 02d22ac756..c9203b2905 100644 --- a/test/passing/refs.janestreet/ite.ml.ref +++ b/test/passing/refs.janestreet/ite.ml.ref @@ -235,3 +235,14 @@ let _ = else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g ;; + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else ( + (* a comment *) + match e with + | A -> a + | B -> b) +;; diff --git a/test/passing/refs.ocamlformat/ite-compact.ml.ref b/test/passing/refs.ocamlformat/ite-compact.ml.ref index 4860d9f001..83155c2a00 100644 --- a/test/passing/refs.ocamlformat/ite-compact.ml.ref +++ b/test/passing/refs.ocamlformat/ite-compact.ml.ref @@ -222,3 +222,11 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with A -> a | B -> b diff --git a/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref b/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref index d7fb7bea79..8419952288 100644 --- a/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref @@ -232,3 +232,11 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with A -> a | B -> b diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref index dba064e102..7893174529 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref @@ -262,9 +262,9 @@ let _ = b else (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - match x with - | A -> - f + match x with + | A -> + f (* Comment before nested if in then branch - Compact mode oscillation *) let _ = @@ -277,3 +277,16 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + match e with + | A -> + a + | B -> + b diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref index fda9f31bfd..3a55cb14ea 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref @@ -267,9 +267,9 @@ let _ = b else (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - match x with - | A -> - f + match x with + | A -> + f (* Comment before nested if in then branch - Compact mode oscillation *) let _ = @@ -282,3 +282,16 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + match e with + | A -> + a + | B -> + b diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref index 5faeb08f42..3fcdd46a97 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref @@ -259,9 +259,9 @@ let _ = b else (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - match x with - | A -> - f + match x with + | A -> + f (* Comment before nested if in then branch - Compact mode oscillation *) let _ = @@ -274,3 +274,16 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + match e with + | A -> + a + | B -> + b diff --git a/test/passing/refs.ocamlformat/ite-kr.ml.ref b/test/passing/refs.ocamlformat/ite-kr.ml.ref index 7a8ac0e004..eeb42049d5 100644 --- a/test/passing/refs.ocamlformat/ite-kr.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kr.ml.ref @@ -308,3 +308,11 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) match e with A -> a | B -> b diff --git a/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref b/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref index ca04feee60..698fa891f1 100644 --- a/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref @@ -312,3 +312,11 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) match e with A -> a | B -> b diff --git a/test/passing/refs.ocamlformat/ite-kw_first.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first.ml.ref index df8130036d..e84a2754f5 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first.ml.ref @@ -258,3 +258,16 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else + (* a comment *) + match e with + | A -> + a + | B -> + b diff --git a/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref index b10567c2e3..a530a75e19 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref @@ -268,3 +268,16 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else + (* a comment *) + match e with + | A -> + a + | B -> + b diff --git a/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref index 1644f1dd7d..cd91623c5d 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref @@ -255,3 +255,16 @@ let _ = then iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond + then x + else + (* a comment *) + match e with + | A -> + a + | B -> + b diff --git a/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref index 8665872059..fcd8a67fda 100644 --- a/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref @@ -219,3 +219,11 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with A -> a | B -> b diff --git a/test/passing/refs.ocamlformat/ite-vertical.ml.ref b/test/passing/refs.ocamlformat/ite-vertical.ml.ref index 8108fa2e00..eec3519ff7 100644 --- a/test/passing/refs.ocamlformat/ite-vertical.ml.ref +++ b/test/passing/refs.ocamlformat/ite-vertical.ml.ref @@ -318,3 +318,16 @@ let _ = iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then + x + else + (* a comment *) + match e with + | A -> + a + | B -> + b diff --git a/test/passing/refs.ocamlformat/ite.ml.ref b/test/passing/refs.ocamlformat/ite.ml.ref index 4860d9f001..83155c2a00 100644 --- a/test/passing/refs.ocamlformat/ite.ml.ref +++ b/test/passing/refs.ocamlformat/ite.ml.ref @@ -222,3 +222,11 @@ let _ = iter (i + 1) ~a:s ~b:a ~c:b ~d:c ~fa:fs ~fb:fa ~fc:fb mflag else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with A -> a | B -> b diff --git a/test/passing/tests/ite.ml b/test/passing/tests/ite.ml index 0bdab6413b..7e478ce9a5 100644 --- a/test/passing/tests/ite.ml +++ b/test/passing/tests/ite.ml @@ -227,3 +227,13 @@ let _ = else iter (i + 1) ~a ~b:s ~c:b ~d:c ~fa ~fb:fs ~fc:fb mflag else g + +(* Short comment before a bare match in the else branch: the match must stay + indented under the comment, not pushed to its end column (regression test) *) +let _ = + if cond then x + else + (* a comment *) + match e with + | A -> a + | B -> b From e3babbb124315a01874d372c0e271cfd56068cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Wed, 24 Jun 2026 10:28:15 +0200 Subject: [PATCH 3/7] Fix begin match/if branch layout with fit-or-vertical MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With `if-then-else=fit-or-vertical`, an `else begin match … with … end` branch rendered the header split over several lines (`begin match` / scrutinee / `with`), `begin if … end` likewise, and `end` ended up less indented than `begin`. For the `begin match/try/function/if end` shortcut, `fmt_beginend` threaded the branch `pro` into the inner expression's `pro`. In fit-or-vertical (and vertical) that `pro` is a `break_unless_newline 1000`, and because the inner expression's ctx0 is the begin/end node, `match_inner_pro` places it inside the header box. `pp_print_or_newline` enqueues its full width (1000) as the token length, so the header box never fits and is forced to break. When the begin/end is an if-then-else branch, emit `pro` outside the box (the branch break already positions it) and wrap the body and `end` together so `end` lines up with `begin`. Other contexts (e.g. `map x begin fun … end`) keep `pro` inside to preserve their indentation. Co-Authored-By: Claude Opus 4.8 (1M context) --- CHANGES.md | 5 ++++ lib/Fmt_ast.ml | 25 ++++++++++++++----- test/passing/refs.ahrefs/ite-compact.ml.ref | 11 ++++++++ .../refs.ahrefs/ite-compact_closing.ml.ref | 11 ++++++++ .../refs.ahrefs/ite-fit_or_vertical.ml.err | 2 +- .../refs.ahrefs/ite-fit_or_vertical.ml.ref | 19 ++++++++++---- .../ite-fit_or_vertical_closing.ml.err | 2 +- .../ite-fit_or_vertical_closing.ml.ref | 19 ++++++++++---- .../ite-fit_or_vertical_no_indicate.ml.err | 2 +- .../ite-fit_or_vertical_no_indicate.ml.ref | 19 ++++++++++---- test/passing/refs.ahrefs/ite-kr.ml.ref | 14 ++++++++++- .../passing/refs.ahrefs/ite-kr_closing.ml.ref | 14 ++++++++++- test/passing/refs.ahrefs/ite-kw_first.ml.ref | 12 +++++++++ .../refs.ahrefs/ite-kw_first_closing.ml.ref | 12 +++++++++ .../ite-kw_first_no_indicate.ml.ref | 12 +++++++++ .../refs.ahrefs/ite-no_indicate.ml.ref | 11 ++++++++ test/passing/refs.ahrefs/ite-vertical.ml.err | 2 +- test/passing/refs.ahrefs/ite-vertical.ml.ref | 16 +++++++++--- test/passing/refs.ahrefs/ite.ml.ref | 11 ++++++++ test/passing/refs.default/ite-compact.ml.ref | 11 ++++++++ .../refs.default/ite-compact_closing.ml.ref | 11 ++++++++ .../refs.default/ite-fit_or_vertical.ml.err | 2 +- .../refs.default/ite-fit_or_vertical.ml.ref | 19 ++++++++++---- .../ite-fit_or_vertical_closing.ml.err | 2 +- .../ite-fit_or_vertical_closing.ml.ref | 19 ++++++++++---- .../ite-fit_or_vertical_no_indicate.ml.err | 2 +- .../ite-fit_or_vertical_no_indicate.ml.ref | 19 ++++++++++---- test/passing/refs.default/ite-kr.ml.ref | 14 ++++++++++- .../refs.default/ite-kr_closing.ml.ref | 14 ++++++++++- test/passing/refs.default/ite-kw_first.ml.ref | 12 +++++++++ .../refs.default/ite-kw_first_closing.ml.ref | 12 +++++++++ .../ite-kw_first_no_indicate.ml.ref | 12 +++++++++ .../refs.default/ite-no_indicate.ml.ref | 11 ++++++++ test/passing/refs.default/ite-vertical.ml.err | 2 +- test/passing/refs.default/ite-vertical.ml.ref | 16 +++++++++--- test/passing/refs.default/ite.ml.ref | 11 ++++++++ .../refs.janestreet/ite-compact.ml.ref | 11 ++++++++ .../ite-compact_closing.ml.ref | 12 +++++++++ .../ite-fit_or_vertical.ml.ref | 12 +++++++++ .../ite-fit_or_vertical_closing.ml.ref | 13 ++++++++++ .../ite-fit_or_vertical_no_indicate.ml.ref | 12 +++++++++ test/passing/refs.janestreet/ite-kr.ml.ref | 13 ++++++++++ .../refs.janestreet/ite-kr_closing.ml.ref | 13 ++++++++++ .../refs.janestreet/ite-kw_first.ml.ref | 12 +++++++++ .../ite-kw_first_closing.ml.ref | 13 ++++++++++ .../ite-kw_first_no_indicate.ml.ref | 12 +++++++++ .../refs.janestreet/ite-no_indicate.ml.ref | 11 ++++++++ .../refs.janestreet/ite-vertical.ml.ref | 12 +++++++++ test/passing/refs.janestreet/ite.ml.ref | 11 ++++++++ .../refs.ocamlformat/ite-compact.ml.ref | 13 ++++++++++ .../ite-compact_closing.ml.ref | 13 ++++++++++ .../ite-fit_or_vertical.ml.err | 2 +- .../ite-fit_or_vertical.ml.ref | 21 ++++++++++++---- .../ite-fit_or_vertical_closing.ml.err | 2 +- .../ite-fit_or_vertical_closing.ml.ref | 21 ++++++++++++---- .../ite-fit_or_vertical_no_indicate.ml.err | 2 +- .../ite-fit_or_vertical_no_indicate.ml.ref | 21 ++++++++++++---- test/passing/refs.ocamlformat/ite-kr.ml.ref | 16 +++++++++++- .../refs.ocamlformat/ite-kr_closing.ml.ref | 16 +++++++++++- .../refs.ocamlformat/ite-kw_first.ml.ref | 14 +++++++++++ .../ite-kw_first_closing.ml.ref | 14 +++++++++++ .../ite-kw_first_no_indicate.ml.ref | 14 +++++++++++ .../refs.ocamlformat/ite-no_indicate.ml.ref | 13 ++++++++++ .../refs.ocamlformat/ite-vertical.ml.err | 2 +- .../refs.ocamlformat/ite-vertical.ml.ref | 18 ++++++++++--- test/passing/refs.ocamlformat/ite.ml.ref | 13 ++++++++++ test/passing/tests/ite.ml | 11 ++++++++ 67 files changed, 713 insertions(+), 78 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b72c1fcfd1..9f1e0bcb3f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,11 @@ profile. This started with version 0.26.0. ### Fixed +- Fix `begin match … end` (and `begin if … end`) branch with + `if-then-else=fit-or-vertical`: the `match … with` header no longer splits + over several lines, and `end` is aligned with `begin`. + (#2810, @MisterDA) + - Fix indentation of a bare `match`/`function`/`try` branch preceded by a comment with `if-then-else=fit-or-vertical`: the branch is no longer indented relative to the comment's end column. diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index a4c8cb21db..e8a8102e3d 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -3038,12 +3038,25 @@ and fmt_beginend c ~loc ?(box = true) ?(pro = noop) ~ctx ~ctx0 ~fmt_atrs cmts_before $ match e.pexp_desc with - | Pexp_match _ | Pexp_try _ | Pexp_function _ | Pexp_ifthenelse _ -> - beginend_box - (fmt_expression c - ~pro:(pro $ begin_ $ str " ") - ~box:false ?eol ~parens:false ~indent_wrap (sub_exp ~ctx e) ) - $ end_ + | Pexp_match _ | Pexp_try _ | Pexp_function _ | Pexp_ifthenelse _ -> ( + let body ~pro = + beginend_box + (fmt_expression c + ~pro:(pro $ begin_ $ str " ") + ~box:false ?eol ~parens:false ~indent_wrap (sub_exp ~ctx e) ) + in + match ctx0 with + | Exp {pexp_desc= Pexp_ifthenelse _; _} -> + (* In an [if-then-else] branch [pro] is the branch break, which for + [if-then-else=fit-or-vertical] is a wide [break_unless_newline]. + Threading it into the inner expression's [pro] would inflate the + header box's width and wrongly break it (e.g. [begin match] / + [x] / [with]); the branch break already placed us, so emit it + outside. The [begin] is then indented by the branch break while + [end] would follow the enclosing box, so wrap both in a box to + keep [end] aligned with [begin]. *) + pro $ hvbox 0 (body ~pro:noop $ end_) + | _ -> body ~pro $ end_ ) | _ -> beginend_box ( hvbox 0 (pro $ begin_) diff --git a/test/passing/refs.ahrefs/ite-compact.ml.ref b/test/passing/refs.ahrefs/ite-compact.ml.ref index 5cecf62364..b1fcd51376 100644 --- a/test/passing/refs.ahrefs/ite-compact.ml.ref +++ b/test/passing/refs.ahrefs/ite-compact.ml.ref @@ -240,3 +240,14 @@ let _ = match e with | A -> a | B -> b) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-compact_closing.ml.ref b/test/passing/refs.ahrefs/ite-compact_closing.ml.ref index afecf296ca..689eb28a10 100644 --- a/test/passing/refs.ahrefs/ite-compact_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-compact_closing.ml.ref @@ -261,3 +261,14 @@ let _ = | A -> a | B -> b ) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.err b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.err index fc51770a03..c19dc1cebd 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.err +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical.ml:116 exceeds the margin Warning: ite-fit_or_vertical.ml:121 exceeds the margin Warning: ite-fit_or_vertical.ml:126 exceeds the margin Warning: ite-fit_or_vertical.ml:247 exceeds the margin -Warning: ite-fit_or_vertical.ml:260 exceeds the margin +Warning: ite-fit_or_vertical.ml:257 exceeds the margin diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref index 588060ddaa..08ff61b043 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref @@ -246,11 +246,8 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b - end + begin if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -284,3 +281,15 @@ let _ = match e with | A -> a | B -> b) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.err b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.err index 5fedffb9e3..357f0a1a12 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.err +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.err @@ -1,2 +1,2 @@ Warning: ite-fit_or_vertical_closing.ml:257 exceeds the margin -Warning: ite-fit_or_vertical_closing.ml:270 exceeds the margin +Warning: ite-fit_or_vertical_closing.ml:267 exceeds the margin diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref index dda0cc0440..7e4199b125 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref @@ -256,11 +256,8 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b - end + begin if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -296,3 +293,15 @@ let _ = | A -> a | B -> b ) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.err b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.err index 9eff570afe..7a8b20a690 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.err +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical_no_indicate.ml:116 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:121 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:126 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:247 exceeds the margin -Warning: ite-fit_or_vertical_no_indicate.ml:260 exceeds the margin +Warning: ite-fit_or_vertical_no_indicate.ml:257 exceeds the margin diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref index 588060ddaa..08ff61b043 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref @@ -246,11 +246,8 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b - end + begin if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -284,3 +281,15 @@ let _ = match e with | A -> a | B -> b) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-kr.ml.ref b/test/passing/refs.ahrefs/ite-kr.ml.ref index 073ec2f740..17b9e67704 100644 --- a/test/passing/refs.ahrefs/ite-kr.ml.ref +++ b/test/passing/refs.ahrefs/ite-kr.ml.ref @@ -286,7 +286,7 @@ let f = if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) begin if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -322,3 +322,15 @@ let _ = | A -> a | B -> b ) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-kr_closing.ml.ref b/test/passing/refs.ahrefs/ite-kr_closing.ml.ref index 7162d363d9..5a12e53cdf 100644 --- a/test/passing/refs.ahrefs/ite-kr_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-kr_closing.ml.ref @@ -293,7 +293,7 @@ let f = if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) begin if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -329,3 +329,15 @@ let _ = | A -> a | B -> b ) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-kw_first.ml.ref b/test/passing/refs.ahrefs/ite-kw_first.ml.ref index 572b9ec54d..2db49482f3 100644 --- a/test/passing/refs.ahrefs/ite-kw_first.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first.ml.ref @@ -276,3 +276,15 @@ let _ = match e with | A -> a | B -> b) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref b/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref index 90ba78b33e..2f6e053a56 100644 --- a/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref @@ -297,3 +297,15 @@ let _ = | A -> a | B -> b ) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref index 572b9ec54d..2db49482f3 100644 --- a/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref @@ -276,3 +276,15 @@ let _ = match e with | A -> a | B -> b) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-no_indicate.ml.ref index 5cecf62364..b1fcd51376 100644 --- a/test/passing/refs.ahrefs/ite-no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-no_indicate.ml.ref @@ -240,3 +240,14 @@ let _ = match e with | A -> a | B -> b) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-vertical.ml.err b/test/passing/refs.ahrefs/ite-vertical.ml.err index b2aa89ed3a..9e3cea0178 100644 --- a/test/passing/refs.ahrefs/ite-vertical.ml.err +++ b/test/passing/refs.ahrefs/ite-vertical.ml.err @@ -2,4 +2,4 @@ Warning: ite-vertical.ml:131 exceeds the margin Warning: ite-vertical.ml:136 exceeds the margin Warning: ite-vertical.ml:141 exceeds the margin Warning: ite-vertical.ml:284 exceeds the margin -Warning: ite-vertical.ml:297 exceeds the margin +Warning: ite-vertical.ml:295 exceeds the margin diff --git a/test/passing/refs.ahrefs/ite-vertical.ml.ref b/test/passing/refs.ahrefs/ite-vertical.ml.ref index 57f3f40112..50e2b6f33f 100644 --- a/test/passing/refs.ahrefs/ite-vertical.ml.ref +++ b/test/passing/refs.ahrefs/ite-vertical.ml.ref @@ -283,9 +283,7 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then + begin if a then b end @@ -321,3 +319,15 @@ let _ = match e with | A -> a | B -> b) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite.ml.ref b/test/passing/refs.ahrefs/ite.ml.ref index 5cecf62364..b1fcd51376 100644 --- a/test/passing/refs.ahrefs/ite.ml.ref +++ b/test/passing/refs.ahrefs/ite.ml.ref @@ -240,3 +240,14 @@ let _ = match e with | A -> a | B -> b) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-compact.ml.ref b/test/passing/refs.default/ite-compact.ml.ref index 2bb4a004b3..5efa7ec0d7 100644 --- a/test/passing/refs.default/ite-compact.ml.ref +++ b/test/passing/refs.default/ite-compact.ml.ref @@ -231,3 +231,14 @@ let _ = else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-compact_closing.ml.ref b/test/passing/refs.default/ite-compact_closing.ml.ref index a738e1750c..58e84d7421 100644 --- a/test/passing/refs.default/ite-compact_closing.ml.ref +++ b/test/passing/refs.default/ite-compact_closing.ml.ref @@ -246,3 +246,14 @@ let _ = else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-fit_or_vertical.ml.err b/test/passing/refs.default/ite-fit_or_vertical.ml.err index 19b7a99c10..6dd85c4c82 100644 --- a/test/passing/refs.default/ite-fit_or_vertical.ml.err +++ b/test/passing/refs.default/ite-fit_or_vertical.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical.ml:115 exceeds the margin Warning: ite-fit_or_vertical.ml:120 exceeds the margin Warning: ite-fit_or_vertical.ml:125 exceeds the margin Warning: ite-fit_or_vertical.ml:247 exceeds the margin -Warning: ite-fit_or_vertical.ml:260 exceeds the margin +Warning: ite-fit_or_vertical.ml:257 exceeds the margin diff --git a/test/passing/refs.default/ite-fit_or_vertical.ml.ref b/test/passing/refs.default/ite-fit_or_vertical.ml.ref index 6823b0ea2b..867aad2f93 100644 --- a/test/passing/refs.default/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical.ml.ref @@ -246,11 +246,8 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b - end + begin if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -284,3 +281,15 @@ let _ = match e with | A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.err b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.err index 126313710f..2be0bcc178 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.err +++ b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.err @@ -1,2 +1,2 @@ Warning: ite-fit_or_vertical_closing.ml:256 exceeds the margin -Warning: ite-fit_or_vertical_closing.ml:269 exceeds the margin +Warning: ite-fit_or_vertical_closing.ml:266 exceeds the margin diff --git a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref index 2d41da0941..66daf0b8cd 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref @@ -255,11 +255,8 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b - end + begin if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -293,3 +290,15 @@ let _ = match e with | A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.err b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.err index bef0700a1d..3700b779cf 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.err +++ b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical_no_indicate.ml:115 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:120 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:125 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:247 exceeds the margin -Warning: ite-fit_or_vertical_no_indicate.ml:260 exceeds the margin +Warning: ite-fit_or_vertical_no_indicate.ml:257 exceeds the margin diff --git a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref index 6823b0ea2b..867aad2f93 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref @@ -246,11 +246,8 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b - end + begin if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -284,3 +281,15 @@ let _ = match e with | A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-kr.ml.ref b/test/passing/refs.default/ite-kr.ml.ref index 18e5097328..c6ae20b934 100644 --- a/test/passing/refs.default/ite-kr.ml.ref +++ b/test/passing/refs.default/ite-kr.ml.ref @@ -283,7 +283,7 @@ let f = if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) begin if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -314,3 +314,15 @@ let _ = x else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-kr_closing.ml.ref b/test/passing/refs.default/ite-kr_closing.ml.ref index 5a25615277..09c1ce003a 100644 --- a/test/passing/refs.default/ite-kr_closing.ml.ref +++ b/test/passing/refs.default/ite-kr_closing.ml.ref @@ -290,7 +290,7 @@ let f = if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) begin if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -321,3 +321,15 @@ let _ = x else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-kw_first.ml.ref b/test/passing/refs.default/ite-kw_first.ml.ref index 2ed516f897..ce45b448cd 100644 --- a/test/passing/refs.default/ite-kw_first.ml.ref +++ b/test/passing/refs.default/ite-kw_first.ml.ref @@ -270,3 +270,15 @@ let _ = match e with | A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-kw_first_closing.ml.ref b/test/passing/refs.default/ite-kw_first_closing.ml.ref index e1aa0f329d..9936b8b73c 100644 --- a/test/passing/refs.default/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.default/ite-kw_first_closing.ml.ref @@ -285,3 +285,15 @@ let _ = match e with | A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref index 2ed516f897..ce45b448cd 100644 --- a/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref @@ -270,3 +270,15 @@ let _ = match e with | A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-no_indicate.ml.ref b/test/passing/refs.default/ite-no_indicate.ml.ref index 2bb4a004b3..5efa7ec0d7 100644 --- a/test/passing/refs.default/ite-no_indicate.ml.ref +++ b/test/passing/refs.default/ite-no_indicate.ml.ref @@ -231,3 +231,14 @@ let _ = else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-vertical.ml.err b/test/passing/refs.default/ite-vertical.ml.err index 3a6f50f9a7..906b414ced 100644 --- a/test/passing/refs.default/ite-vertical.ml.err +++ b/test/passing/refs.default/ite-vertical.ml.err @@ -2,4 +2,4 @@ Warning: ite-vertical.ml:131 exceeds the margin Warning: ite-vertical.ml:136 exceeds the margin Warning: ite-vertical.ml:141 exceeds the margin Warning: ite-vertical.ml:286 exceeds the margin -Warning: ite-vertical.ml:299 exceeds the margin +Warning: ite-vertical.ml:297 exceeds the margin diff --git a/test/passing/refs.default/ite-vertical.ml.ref b/test/passing/refs.default/ite-vertical.ml.ref index 5c7eb37b9f..a113faacab 100644 --- a/test/passing/refs.default/ite-vertical.ml.ref +++ b/test/passing/refs.default/ite-vertical.ml.ref @@ -285,9 +285,7 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then + begin if a then b end @@ -323,3 +321,15 @@ let _ = match e with | A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite.ml.ref b/test/passing/refs.default/ite.ml.ref index 2bb4a004b3..5efa7ec0d7 100644 --- a/test/passing/refs.default/ite.ml.ref +++ b/test/passing/refs.default/ite.ml.ref @@ -231,3 +231,14 @@ let _ = else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.janestreet/ite-compact.ml.ref b/test/passing/refs.janestreet/ite-compact.ml.ref index c9203b2905..a9bb04fced 100644 --- a/test/passing/refs.janestreet/ite-compact.ml.ref +++ b/test/passing/refs.janestreet/ite-compact.ml.ref @@ -246,3 +246,14 @@ let _ = | A -> a | B -> b) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-compact_closing.ml.ref b/test/passing/refs.janestreet/ite-compact_closing.ml.ref index ea57aa99c5..4c438df481 100644 --- a/test/passing/refs.janestreet/ite-compact_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-compact_closing.ml.ref @@ -262,3 +262,15 @@ let _ = | B -> b ) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref index d2bd3bd125..347d35bb4d 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref @@ -300,3 +300,15 @@ let _ = | A -> a | B -> b) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref index 4ff166ae94..8834bc8e78 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref @@ -313,3 +313,16 @@ let _ = | B -> b ) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref index d2bd3bd125..347d35bb4d 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref @@ -300,3 +300,15 @@ let _ = | A -> a | B -> b) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-kr.ml.ref b/test/passing/refs.janestreet/ite-kr.ml.ref index 29b1c8a72e..8914e9364b 100644 --- a/test/passing/refs.janestreet/ite-kr.ml.ref +++ b/test/passing/refs.janestreet/ite-kr.ml.ref @@ -349,3 +349,16 @@ let _ = | B -> b ) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-kr_closing.ml.ref b/test/passing/refs.janestreet/ite-kr_closing.ml.ref index 8f916d8755..62a53ce1fa 100644 --- a/test/passing/refs.janestreet/ite-kr_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-kr_closing.ml.ref @@ -356,3 +356,16 @@ let _ = | B -> b ) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-kw_first.ml.ref b/test/passing/refs.janestreet/ite-kw_first.ml.ref index 7eccbbf131..676e727232 100644 --- a/test/passing/refs.janestreet/ite-kw_first.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first.ml.ref @@ -281,3 +281,15 @@ let _ = | A -> a | B -> b) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref b/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref index 0b2eea44e3..42bb8cbc7b 100644 --- a/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref @@ -297,3 +297,16 @@ let _ = | B -> b ) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref index 7eccbbf131..676e727232 100644 --- a/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref @@ -281,3 +281,15 @@ let _ = | A -> a | B -> b) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-no_indicate.ml.ref b/test/passing/refs.janestreet/ite-no_indicate.ml.ref index c9203b2905..a9bb04fced 100644 --- a/test/passing/refs.janestreet/ite-no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-no_indicate.ml.ref @@ -246,3 +246,14 @@ let _ = | A -> a | B -> b) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-vertical.ml.ref b/test/passing/refs.janestreet/ite-vertical.ml.ref index ca83aeaa78..ed633fe784 100644 --- a/test/passing/refs.janestreet/ite-vertical.ml.ref +++ b/test/passing/refs.janestreet/ite-vertical.ml.ref @@ -345,3 +345,15 @@ let _ = | A -> a | B -> b) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite.ml.ref b/test/passing/refs.janestreet/ite.ml.ref index c9203b2905..a9bb04fced 100644 --- a/test/passing/refs.janestreet/ite.ml.ref +++ b/test/passing/refs.janestreet/ite.ml.ref @@ -246,3 +246,14 @@ let _ = | A -> a | B -> b) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.ocamlformat/ite-compact.ml.ref b/test/passing/refs.ocamlformat/ite-compact.ml.ref index 83155c2a00..5687e9ada6 100644 --- a/test/passing/refs.ocamlformat/ite-compact.ml.ref +++ b/test/passing/refs.ocamlformat/ite-compact.ml.ref @@ -230,3 +230,16 @@ let _ = else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref b/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref index 8419952288..e85fe9c675 100644 --- a/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref @@ -240,3 +240,16 @@ let _ = else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.err b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.err index 35c4dd8d0a..65da7bfbf6 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.err +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.err @@ -1,2 +1,2 @@ Warning: ite-fit_or_vertical.ml:250 exceeds the margin -Warning: ite-fit_or_vertical.ml:263 exceeds the margin +Warning: ite-fit_or_vertical.ml:260 exceeds the margin diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref index 7893174529..4d8026965e 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref @@ -249,11 +249,8 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b - end + begin if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -290,3 +287,17 @@ let _ = a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.err b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.err index 23c64dbaf7..7fd8ac1f7b 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.err +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.err @@ -1,2 +1,2 @@ Warning: ite-fit_or_vertical_closing.ml:255 exceeds the margin -Warning: ite-fit_or_vertical_closing.ml:268 exceeds the margin +Warning: ite-fit_or_vertical_closing.ml:265 exceeds the margin diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref index 3a55cb14ea..abee088908 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref @@ -254,11 +254,8 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b - end + begin if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -295,3 +292,17 @@ let _ = a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.err b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.err index 0ef658ec2b..55504ff751 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.err +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical_no_indicate.ml:110 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:115 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:120 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:247 exceeds the margin -Warning: ite-fit_or_vertical_no_indicate.ml:260 exceeds the margin +Warning: ite-fit_or_vertical_no_indicate.ml:257 exceeds the margin diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref index 3fcdd46a97..0ca6b28101 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref @@ -246,11 +246,8 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b - end + begin if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -287,3 +284,17 @@ let _ = a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-kr.ml.ref b/test/passing/refs.ocamlformat/ite-kr.ml.ref index eeb42049d5..9005a6673c 100644 --- a/test/passing/refs.ocamlformat/ite-kr.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kr.ml.ref @@ -284,7 +284,7 @@ let f = if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) begin if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -316,3 +316,17 @@ let _ = x else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref b/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref index 698fa891f1..2cb27ad0b4 100644 --- a/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref @@ -288,7 +288,7 @@ let f = if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) begin if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -320,3 +320,17 @@ let _ = x else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-kw_first.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first.ml.ref index e84a2754f5..785f40fa79 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first.ml.ref @@ -271,3 +271,17 @@ let _ = a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref index a530a75e19..c248800163 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref @@ -281,3 +281,17 @@ let _ = a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref index cd91623c5d..e0fffd99e5 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref @@ -268,3 +268,17 @@ let _ = a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref index fcd8a67fda..75e34eafb5 100644 --- a/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref @@ -227,3 +227,16 @@ let _ = else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-vertical.ml.err b/test/passing/refs.ocamlformat/ite-vertical.ml.err index 6d93e7b45d..94ff935b4d 100644 --- a/test/passing/refs.ocamlformat/ite-vertical.ml.err +++ b/test/passing/refs.ocamlformat/ite-vertical.ml.err @@ -1,2 +1,2 @@ Warning: ite-vertical.ml:291 exceeds the margin -Warning: ite-vertical.ml:304 exceeds the margin +Warning: ite-vertical.ml:302 exceeds the margin diff --git a/test/passing/refs.ocamlformat/ite-vertical.ml.ref b/test/passing/refs.ocamlformat/ite-vertical.ml.ref index eec3519ff7..6856d08a9f 100644 --- a/test/passing/refs.ocamlformat/ite-vertical.ml.ref +++ b/test/passing/refs.ocamlformat/ite-vertical.ml.ref @@ -290,9 +290,7 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then + begin if a then b end @@ -331,3 +329,17 @@ let _ = a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite.ml.ref b/test/passing/refs.ocamlformat/ite.ml.ref index 83155c2a00..5687e9ada6 100644 --- a/test/passing/refs.ocamlformat/ite.ml.ref +++ b/test/passing/refs.ocamlformat/ite.ml.ref @@ -230,3 +230,16 @@ let _ = else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/tests/ite.ml b/test/passing/tests/ite.ml index 7e478ce9a5..71796f892e 100644 --- a/test/passing/tests/ite.ml +++ b/test/passing/tests/ite.ml @@ -237,3 +237,14 @@ let _ = match e with | A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else begin + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end From 26c1058d86107d48baaa2b7137b7b1f8ca70a9b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Wed, 24 Jun 2026 16:08:08 +0200 Subject: [PATCH 4/7] Revert "Fix begin match/if branch layout with fit-or-vertical" This reverts commit e3babbb124315a01874d372c0e271cfd56068cf7. --- CHANGES.md | 5 ---- lib/Fmt_ast.ml | 25 +++++-------------- test/passing/refs.ahrefs/ite-compact.ml.ref | 11 -------- .../refs.ahrefs/ite-compact_closing.ml.ref | 11 -------- .../refs.ahrefs/ite-fit_or_vertical.ml.err | 2 +- .../refs.ahrefs/ite-fit_or_vertical.ml.ref | 19 ++++---------- .../ite-fit_or_vertical_closing.ml.err | 2 +- .../ite-fit_or_vertical_closing.ml.ref | 19 ++++---------- .../ite-fit_or_vertical_no_indicate.ml.err | 2 +- .../ite-fit_or_vertical_no_indicate.ml.ref | 19 ++++---------- test/passing/refs.ahrefs/ite-kr.ml.ref | 14 +---------- .../passing/refs.ahrefs/ite-kr_closing.ml.ref | 14 +---------- test/passing/refs.ahrefs/ite-kw_first.ml.ref | 12 --------- .../refs.ahrefs/ite-kw_first_closing.ml.ref | 12 --------- .../ite-kw_first_no_indicate.ml.ref | 12 --------- .../refs.ahrefs/ite-no_indicate.ml.ref | 11 -------- test/passing/refs.ahrefs/ite-vertical.ml.err | 2 +- test/passing/refs.ahrefs/ite-vertical.ml.ref | 16 +++--------- test/passing/refs.ahrefs/ite.ml.ref | 11 -------- test/passing/refs.default/ite-compact.ml.ref | 11 -------- .../refs.default/ite-compact_closing.ml.ref | 11 -------- .../refs.default/ite-fit_or_vertical.ml.err | 2 +- .../refs.default/ite-fit_or_vertical.ml.ref | 19 ++++---------- .../ite-fit_or_vertical_closing.ml.err | 2 +- .../ite-fit_or_vertical_closing.ml.ref | 19 ++++---------- .../ite-fit_or_vertical_no_indicate.ml.err | 2 +- .../ite-fit_or_vertical_no_indicate.ml.ref | 19 ++++---------- test/passing/refs.default/ite-kr.ml.ref | 14 +---------- .../refs.default/ite-kr_closing.ml.ref | 14 +---------- test/passing/refs.default/ite-kw_first.ml.ref | 12 --------- .../refs.default/ite-kw_first_closing.ml.ref | 12 --------- .../ite-kw_first_no_indicate.ml.ref | 12 --------- .../refs.default/ite-no_indicate.ml.ref | 11 -------- test/passing/refs.default/ite-vertical.ml.err | 2 +- test/passing/refs.default/ite-vertical.ml.ref | 16 +++--------- test/passing/refs.default/ite.ml.ref | 11 -------- .../refs.janestreet/ite-compact.ml.ref | 11 -------- .../ite-compact_closing.ml.ref | 12 --------- .../ite-fit_or_vertical.ml.ref | 12 --------- .../ite-fit_or_vertical_closing.ml.ref | 13 ---------- .../ite-fit_or_vertical_no_indicate.ml.ref | 12 --------- test/passing/refs.janestreet/ite-kr.ml.ref | 13 ---------- .../refs.janestreet/ite-kr_closing.ml.ref | 13 ---------- .../refs.janestreet/ite-kw_first.ml.ref | 12 --------- .../ite-kw_first_closing.ml.ref | 13 ---------- .../ite-kw_first_no_indicate.ml.ref | 12 --------- .../refs.janestreet/ite-no_indicate.ml.ref | 11 -------- .../refs.janestreet/ite-vertical.ml.ref | 12 --------- test/passing/refs.janestreet/ite.ml.ref | 11 -------- .../refs.ocamlformat/ite-compact.ml.ref | 13 ---------- .../ite-compact_closing.ml.ref | 13 ---------- .../ite-fit_or_vertical.ml.err | 2 +- .../ite-fit_or_vertical.ml.ref | 21 ++++------------ .../ite-fit_or_vertical_closing.ml.err | 2 +- .../ite-fit_or_vertical_closing.ml.ref | 21 ++++------------ .../ite-fit_or_vertical_no_indicate.ml.err | 2 +- .../ite-fit_or_vertical_no_indicate.ml.ref | 21 ++++------------ test/passing/refs.ocamlformat/ite-kr.ml.ref | 16 +----------- .../refs.ocamlformat/ite-kr_closing.ml.ref | 16 +----------- .../refs.ocamlformat/ite-kw_first.ml.ref | 14 ----------- .../ite-kw_first_closing.ml.ref | 14 ----------- .../ite-kw_first_no_indicate.ml.ref | 14 ----------- .../refs.ocamlformat/ite-no_indicate.ml.ref | 13 ---------- .../refs.ocamlformat/ite-vertical.ml.err | 2 +- .../refs.ocamlformat/ite-vertical.ml.ref | 18 +++---------- test/passing/refs.ocamlformat/ite.ml.ref | 13 ---------- test/passing/tests/ite.ml | 11 -------- 67 files changed, 78 insertions(+), 713 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9f1e0bcb3f..b72c1fcfd1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,11 +8,6 @@ profile. This started with version 0.26.0. ### Fixed -- Fix `begin match … end` (and `begin if … end`) branch with - `if-then-else=fit-or-vertical`: the `match … with` header no longer splits - over several lines, and `end` is aligned with `begin`. - (#2810, @MisterDA) - - Fix indentation of a bare `match`/`function`/`try` branch preceded by a comment with `if-then-else=fit-or-vertical`: the branch is no longer indented relative to the comment's end column. diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index e8a8102e3d..a4c8cb21db 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -3038,25 +3038,12 @@ and fmt_beginend c ~loc ?(box = true) ?(pro = noop) ~ctx ~ctx0 ~fmt_atrs cmts_before $ match e.pexp_desc with - | Pexp_match _ | Pexp_try _ | Pexp_function _ | Pexp_ifthenelse _ -> ( - let body ~pro = - beginend_box - (fmt_expression c - ~pro:(pro $ begin_ $ str " ") - ~box:false ?eol ~parens:false ~indent_wrap (sub_exp ~ctx e) ) - in - match ctx0 with - | Exp {pexp_desc= Pexp_ifthenelse _; _} -> - (* In an [if-then-else] branch [pro] is the branch break, which for - [if-then-else=fit-or-vertical] is a wide [break_unless_newline]. - Threading it into the inner expression's [pro] would inflate the - header box's width and wrongly break it (e.g. [begin match] / - [x] / [with]); the branch break already placed us, so emit it - outside. The [begin] is then indented by the branch break while - [end] would follow the enclosing box, so wrap both in a box to - keep [end] aligned with [begin]. *) - pro $ hvbox 0 (body ~pro:noop $ end_) - | _ -> body ~pro $ end_ ) + | Pexp_match _ | Pexp_try _ | Pexp_function _ | Pexp_ifthenelse _ -> + beginend_box + (fmt_expression c + ~pro:(pro $ begin_ $ str " ") + ~box:false ?eol ~parens:false ~indent_wrap (sub_exp ~ctx e) ) + $ end_ | _ -> beginend_box ( hvbox 0 (pro $ begin_) diff --git a/test/passing/refs.ahrefs/ite-compact.ml.ref b/test/passing/refs.ahrefs/ite-compact.ml.ref index b1fcd51376..5cecf62364 100644 --- a/test/passing/refs.ahrefs/ite-compact.ml.ref +++ b/test/passing/refs.ahrefs/ite-compact.ml.ref @@ -240,14 +240,3 @@ let _ = match e with | A -> a | B -> b) - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.ahrefs/ite-compact_closing.ml.ref b/test/passing/refs.ahrefs/ite-compact_closing.ml.ref index 689eb28a10..afecf296ca 100644 --- a/test/passing/refs.ahrefs/ite-compact_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-compact_closing.ml.ref @@ -261,14 +261,3 @@ let _ = | A -> a | B -> b ) - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.err b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.err index c19dc1cebd..fc51770a03 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.err +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical.ml:116 exceeds the margin Warning: ite-fit_or_vertical.ml:121 exceeds the margin Warning: ite-fit_or_vertical.ml:126 exceeds the margin Warning: ite-fit_or_vertical.ml:247 exceeds the margin -Warning: ite-fit_or_vertical.ml:257 exceeds the margin +Warning: ite-fit_or_vertical.ml:260 exceeds the margin diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref index 08ff61b043..588060ddaa 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref @@ -246,8 +246,11 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + begin if + a + then + b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -281,15 +284,3 @@ let _ = match e with | A -> a | B -> b) - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.err b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.err index 357f0a1a12..5fedffb9e3 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.err +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.err @@ -1,2 +1,2 @@ Warning: ite-fit_or_vertical_closing.ml:257 exceeds the margin -Warning: ite-fit_or_vertical_closing.ml:267 exceeds the margin +Warning: ite-fit_or_vertical_closing.ml:270 exceeds the margin diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref index 7e4199b125..dda0cc0440 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref @@ -256,8 +256,11 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + begin if + a + then + b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -293,15 +296,3 @@ let _ = | A -> a | B -> b ) - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.err b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.err index 7a8b20a690..9eff570afe 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.err +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical_no_indicate.ml:116 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:121 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:126 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:247 exceeds the margin -Warning: ite-fit_or_vertical_no_indicate.ml:257 exceeds the margin +Warning: ite-fit_or_vertical_no_indicate.ml:260 exceeds the margin diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref index 08ff61b043..588060ddaa 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref @@ -246,8 +246,11 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + begin if + a + then + b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -281,15 +284,3 @@ let _ = match e with | A -> a | B -> b) - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.ahrefs/ite-kr.ml.ref b/test/passing/refs.ahrefs/ite-kr.ml.ref index 17b9e67704..073ec2f740 100644 --- a/test/passing/refs.ahrefs/ite-kr.ml.ref +++ b/test/passing/refs.ahrefs/ite-kr.ml.ref @@ -286,7 +286,7 @@ let f = if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) begin if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -322,15 +322,3 @@ let _ = | A -> a | B -> b ) - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.ahrefs/ite-kr_closing.ml.ref b/test/passing/refs.ahrefs/ite-kr_closing.ml.ref index 5a12e53cdf..7162d363d9 100644 --- a/test/passing/refs.ahrefs/ite-kr_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-kr_closing.ml.ref @@ -293,7 +293,7 @@ let f = if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) begin if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -329,15 +329,3 @@ let _ = | A -> a | B -> b ) - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.ahrefs/ite-kw_first.ml.ref b/test/passing/refs.ahrefs/ite-kw_first.ml.ref index 2db49482f3..572b9ec54d 100644 --- a/test/passing/refs.ahrefs/ite-kw_first.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first.ml.ref @@ -276,15 +276,3 @@ let _ = match e with | A -> a | B -> b) - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond - then x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref b/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref index 2f6e053a56..90ba78b33e 100644 --- a/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref @@ -297,15 +297,3 @@ let _ = | A -> a | B -> b ) - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond - then x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref index 2db49482f3..572b9ec54d 100644 --- a/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref @@ -276,15 +276,3 @@ let _ = match e with | A -> a | B -> b) - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond - then x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.ahrefs/ite-no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-no_indicate.ml.ref index b1fcd51376..5cecf62364 100644 --- a/test/passing/refs.ahrefs/ite-no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-no_indicate.ml.ref @@ -240,14 +240,3 @@ let _ = match e with | A -> a | B -> b) - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.ahrefs/ite-vertical.ml.err b/test/passing/refs.ahrefs/ite-vertical.ml.err index 9e3cea0178..b2aa89ed3a 100644 --- a/test/passing/refs.ahrefs/ite-vertical.ml.err +++ b/test/passing/refs.ahrefs/ite-vertical.ml.err @@ -2,4 +2,4 @@ Warning: ite-vertical.ml:131 exceeds the margin Warning: ite-vertical.ml:136 exceeds the margin Warning: ite-vertical.ml:141 exceeds the margin Warning: ite-vertical.ml:284 exceeds the margin -Warning: ite-vertical.ml:295 exceeds the margin +Warning: ite-vertical.ml:297 exceeds the margin diff --git a/test/passing/refs.ahrefs/ite-vertical.ml.ref b/test/passing/refs.ahrefs/ite-vertical.ml.ref index 50e2b6f33f..57f3f40112 100644 --- a/test/passing/refs.ahrefs/ite-vertical.ml.ref +++ b/test/passing/refs.ahrefs/ite-vertical.ml.ref @@ -283,7 +283,9 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then + begin if + a + then b end @@ -319,15 +321,3 @@ let _ = match e with | A -> a | B -> b) - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.ahrefs/ite.ml.ref b/test/passing/refs.ahrefs/ite.ml.ref index b1fcd51376..5cecf62364 100644 --- a/test/passing/refs.ahrefs/ite.ml.ref +++ b/test/passing/refs.ahrefs/ite.ml.ref @@ -240,14 +240,3 @@ let _ = match e with | A -> a | B -> b) - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.default/ite-compact.ml.ref b/test/passing/refs.default/ite-compact.ml.ref index 5efa7ec0d7..2bb4a004b3 100644 --- a/test/passing/refs.default/ite-compact.ml.ref +++ b/test/passing/refs.default/ite-compact.ml.ref @@ -231,14 +231,3 @@ let _ = else (* a comment *) match e with A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.default/ite-compact_closing.ml.ref b/test/passing/refs.default/ite-compact_closing.ml.ref index 58e84d7421..a738e1750c 100644 --- a/test/passing/refs.default/ite-compact_closing.ml.ref +++ b/test/passing/refs.default/ite-compact_closing.ml.ref @@ -246,14 +246,3 @@ let _ = else (* a comment *) match e with A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.default/ite-fit_or_vertical.ml.err b/test/passing/refs.default/ite-fit_or_vertical.ml.err index 6dd85c4c82..19b7a99c10 100644 --- a/test/passing/refs.default/ite-fit_or_vertical.ml.err +++ b/test/passing/refs.default/ite-fit_or_vertical.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical.ml:115 exceeds the margin Warning: ite-fit_or_vertical.ml:120 exceeds the margin Warning: ite-fit_or_vertical.ml:125 exceeds the margin Warning: ite-fit_or_vertical.ml:247 exceeds the margin -Warning: ite-fit_or_vertical.ml:257 exceeds the margin +Warning: ite-fit_or_vertical.ml:260 exceeds the margin diff --git a/test/passing/refs.default/ite-fit_or_vertical.ml.ref b/test/passing/refs.default/ite-fit_or_vertical.ml.ref index 867aad2f93..6823b0ea2b 100644 --- a/test/passing/refs.default/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical.ml.ref @@ -246,8 +246,11 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + begin if + a + then + b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -281,15 +284,3 @@ let _ = match e with | A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.err b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.err index 2be0bcc178..126313710f 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.err +++ b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.err @@ -1,2 +1,2 @@ Warning: ite-fit_or_vertical_closing.ml:256 exceeds the margin -Warning: ite-fit_or_vertical_closing.ml:266 exceeds the margin +Warning: ite-fit_or_vertical_closing.ml:269 exceeds the margin diff --git a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref index 66daf0b8cd..2d41da0941 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref @@ -255,8 +255,11 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + begin if + a + then + b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -290,15 +293,3 @@ let _ = match e with | A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.err b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.err index 3700b779cf..bef0700a1d 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.err +++ b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical_no_indicate.ml:115 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:120 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:125 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:247 exceeds the margin -Warning: ite-fit_or_vertical_no_indicate.ml:257 exceeds the margin +Warning: ite-fit_or_vertical_no_indicate.ml:260 exceeds the margin diff --git a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref index 867aad2f93..6823b0ea2b 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref @@ -246,8 +246,11 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + begin if + a + then + b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -281,15 +284,3 @@ let _ = match e with | A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.default/ite-kr.ml.ref b/test/passing/refs.default/ite-kr.ml.ref index c6ae20b934..18e5097328 100644 --- a/test/passing/refs.default/ite-kr.ml.ref +++ b/test/passing/refs.default/ite-kr.ml.ref @@ -283,7 +283,7 @@ let f = if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) begin if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -314,15 +314,3 @@ let _ = x else (* a comment *) match e with A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.default/ite-kr_closing.ml.ref b/test/passing/refs.default/ite-kr_closing.ml.ref index 09c1ce003a..5a25615277 100644 --- a/test/passing/refs.default/ite-kr_closing.ml.ref +++ b/test/passing/refs.default/ite-kr_closing.ml.ref @@ -290,7 +290,7 @@ let f = if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) begin if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -321,15 +321,3 @@ let _ = x else (* a comment *) match e with A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.default/ite-kw_first.ml.ref b/test/passing/refs.default/ite-kw_first.ml.ref index ce45b448cd..2ed516f897 100644 --- a/test/passing/refs.default/ite-kw_first.ml.ref +++ b/test/passing/refs.default/ite-kw_first.ml.ref @@ -270,15 +270,3 @@ let _ = match e with | A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond - then x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.default/ite-kw_first_closing.ml.ref b/test/passing/refs.default/ite-kw_first_closing.ml.ref index 9936b8b73c..e1aa0f329d 100644 --- a/test/passing/refs.default/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.default/ite-kw_first_closing.ml.ref @@ -285,15 +285,3 @@ let _ = match e with | A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond - then x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref index ce45b448cd..2ed516f897 100644 --- a/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref @@ -270,15 +270,3 @@ let _ = match e with | A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond - then x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.default/ite-no_indicate.ml.ref b/test/passing/refs.default/ite-no_indicate.ml.ref index 5efa7ec0d7..2bb4a004b3 100644 --- a/test/passing/refs.default/ite-no_indicate.ml.ref +++ b/test/passing/refs.default/ite-no_indicate.ml.ref @@ -231,14 +231,3 @@ let _ = else (* a comment *) match e with A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.default/ite-vertical.ml.err b/test/passing/refs.default/ite-vertical.ml.err index 906b414ced..3a6f50f9a7 100644 --- a/test/passing/refs.default/ite-vertical.ml.err +++ b/test/passing/refs.default/ite-vertical.ml.err @@ -2,4 +2,4 @@ Warning: ite-vertical.ml:131 exceeds the margin Warning: ite-vertical.ml:136 exceeds the margin Warning: ite-vertical.ml:141 exceeds the margin Warning: ite-vertical.ml:286 exceeds the margin -Warning: ite-vertical.ml:297 exceeds the margin +Warning: ite-vertical.ml:299 exceeds the margin diff --git a/test/passing/refs.default/ite-vertical.ml.ref b/test/passing/refs.default/ite-vertical.ml.ref index a113faacab..5c7eb37b9f 100644 --- a/test/passing/refs.default/ite-vertical.ml.ref +++ b/test/passing/refs.default/ite-vertical.ml.ref @@ -285,7 +285,9 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then + begin if + a + then b end @@ -321,15 +323,3 @@ let _ = match e with | A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.default/ite.ml.ref b/test/passing/refs.default/ite.ml.ref index 5efa7ec0d7..2bb4a004b3 100644 --- a/test/passing/refs.default/ite.ml.ref +++ b/test/passing/refs.default/ite.ml.ref @@ -231,14 +231,3 @@ let _ = else (* a comment *) match e with A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then x - else - begin match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end diff --git a/test/passing/refs.janestreet/ite-compact.ml.ref b/test/passing/refs.janestreet/ite-compact.ml.ref index a9bb04fced..c9203b2905 100644 --- a/test/passing/refs.janestreet/ite-compact.ml.ref +++ b/test/passing/refs.janestreet/ite-compact.ml.ref @@ -246,14 +246,3 @@ let _ = | A -> a | B -> b) ;; - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then x - else ( - match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b) -;; diff --git a/test/passing/refs.janestreet/ite-compact_closing.ml.ref b/test/passing/refs.janestreet/ite-compact_closing.ml.ref index 4c438df481..ea57aa99c5 100644 --- a/test/passing/refs.janestreet/ite-compact_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-compact_closing.ml.ref @@ -262,15 +262,3 @@ let _ = | B -> b ) ;; - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then x - else ( - match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - ) -;; diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref index 347d35bb4d..d2bd3bd125 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref @@ -300,15 +300,3 @@ let _ = | A -> a | B -> b) ;; - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else ( - match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b) -;; diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref index 8834bc8e78..4ff166ae94 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref @@ -313,16 +313,3 @@ let _ = | B -> b ) ;; - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else ( - match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - ) -;; diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref index 347d35bb4d..d2bd3bd125 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref @@ -300,15 +300,3 @@ let _ = | A -> a | B -> b) ;; - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else ( - match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b) -;; diff --git a/test/passing/refs.janestreet/ite-kr.ml.ref b/test/passing/refs.janestreet/ite-kr.ml.ref index 8914e9364b..29b1c8a72e 100644 --- a/test/passing/refs.janestreet/ite-kr.ml.ref +++ b/test/passing/refs.janestreet/ite-kr.ml.ref @@ -349,16 +349,3 @@ let _ = | B -> b ) ;; - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else ( - match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - ) -;; diff --git a/test/passing/refs.janestreet/ite-kr_closing.ml.ref b/test/passing/refs.janestreet/ite-kr_closing.ml.ref index 62a53ce1fa..8f916d8755 100644 --- a/test/passing/refs.janestreet/ite-kr_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-kr_closing.ml.ref @@ -356,16 +356,3 @@ let _ = | B -> b ) ;; - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else ( - match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - ) -;; diff --git a/test/passing/refs.janestreet/ite-kw_first.ml.ref b/test/passing/refs.janestreet/ite-kw_first.ml.ref index 676e727232..7eccbbf131 100644 --- a/test/passing/refs.janestreet/ite-kw_first.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first.ml.ref @@ -281,15 +281,3 @@ let _ = | A -> a | B -> b) ;; - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond - then x - else ( - match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b) -;; diff --git a/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref b/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref index 42bb8cbc7b..0b2eea44e3 100644 --- a/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref @@ -297,16 +297,3 @@ let _ = | B -> b ) ;; - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond - then x - else ( - match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - ) -;; diff --git a/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref index 676e727232..7eccbbf131 100644 --- a/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref @@ -281,15 +281,3 @@ let _ = | A -> a | B -> b) ;; - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond - then x - else ( - match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b) -;; diff --git a/test/passing/refs.janestreet/ite-no_indicate.ml.ref b/test/passing/refs.janestreet/ite-no_indicate.ml.ref index a9bb04fced..c9203b2905 100644 --- a/test/passing/refs.janestreet/ite-no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-no_indicate.ml.ref @@ -246,14 +246,3 @@ let _ = | A -> a | B -> b) ;; - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then x - else ( - match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b) -;; diff --git a/test/passing/refs.janestreet/ite-vertical.ml.ref b/test/passing/refs.janestreet/ite-vertical.ml.ref index ed633fe784..ca83aeaa78 100644 --- a/test/passing/refs.janestreet/ite-vertical.ml.ref +++ b/test/passing/refs.janestreet/ite-vertical.ml.ref @@ -345,15 +345,3 @@ let _ = | A -> a | B -> b) ;; - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else ( - match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b) -;; diff --git a/test/passing/refs.janestreet/ite.ml.ref b/test/passing/refs.janestreet/ite.ml.ref index a9bb04fced..c9203b2905 100644 --- a/test/passing/refs.janestreet/ite.ml.ref +++ b/test/passing/refs.janestreet/ite.ml.ref @@ -246,14 +246,3 @@ let _ = | A -> a | B -> b) ;; - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then x - else ( - match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b) -;; diff --git a/test/passing/refs.ocamlformat/ite-compact.ml.ref b/test/passing/refs.ocamlformat/ite-compact.ml.ref index 5687e9ada6..83155c2a00 100644 --- a/test/passing/refs.ocamlformat/ite-compact.ml.ref +++ b/test/passing/refs.ocamlformat/ite-compact.ml.ref @@ -230,16 +230,3 @@ let _ = else (* a comment *) match e with A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then x - else - begin match e with - | A -> - function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> - b - end diff --git a/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref b/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref index e85fe9c675..8419952288 100644 --- a/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref @@ -240,16 +240,3 @@ let _ = else (* a comment *) match e with A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then x - else - begin match e with - | A -> - function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> - b - end diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.err b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.err index 65da7bfbf6..35c4dd8d0a 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.err +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.err @@ -1,2 +1,2 @@ Warning: ite-fit_or_vertical.ml:250 exceeds the margin -Warning: ite-fit_or_vertical.ml:260 exceeds the margin +Warning: ite-fit_or_vertical.ml:263 exceeds the margin diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref index 4d8026965e..7893174529 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref @@ -249,8 +249,11 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + begin if + a + then + b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -287,17 +290,3 @@ let _ = a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> - function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> - b - end diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.err b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.err index 7fd8ac1f7b..23c64dbaf7 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.err +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.err @@ -1,2 +1,2 @@ Warning: ite-fit_or_vertical_closing.ml:255 exceeds the margin -Warning: ite-fit_or_vertical_closing.ml:265 exceeds the margin +Warning: ite-fit_or_vertical_closing.ml:268 exceeds the margin diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref index abee088908..3a55cb14ea 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref @@ -254,8 +254,11 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + begin if + a + then + b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -292,17 +295,3 @@ let _ = a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> - function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> - b - end diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.err b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.err index 55504ff751..0ef658ec2b 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.err +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical_no_indicate.ml:110 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:115 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:120 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:247 exceeds the margin -Warning: ite-fit_or_vertical_no_indicate.ml:257 exceeds the margin +Warning: ite-fit_or_vertical_no_indicate.ml:260 exceeds the margin diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref index 0ca6b28101..3fcdd46a97 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref @@ -246,8 +246,11 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + begin if + a + then + b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -284,17 +287,3 @@ let _ = a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> - function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> - b - end diff --git a/test/passing/refs.ocamlformat/ite-kr.ml.ref b/test/passing/refs.ocamlformat/ite-kr.ml.ref index 9005a6673c..eeb42049d5 100644 --- a/test/passing/refs.ocamlformat/ite-kr.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kr.ml.ref @@ -284,7 +284,7 @@ let f = if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) begin if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -316,17 +316,3 @@ let _ = x else (* a comment *) match e with A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> - function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> - b - end diff --git a/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref b/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref index 2cb27ad0b4..698fa891f1 100644 --- a/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref @@ -288,7 +288,7 @@ let f = if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) begin if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -320,17 +320,3 @@ let _ = x else (* a comment *) match e with A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> - function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> - b - end diff --git a/test/passing/refs.ocamlformat/ite-kw_first.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first.ml.ref index 785f40fa79..e84a2754f5 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first.ml.ref @@ -271,17 +271,3 @@ let _ = a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond - then x - else - begin match e with - | A -> - function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> - b - end diff --git a/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref index c248800163..a530a75e19 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref @@ -281,17 +281,3 @@ let _ = a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond - then x - else - begin match e with - | A -> - function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> - b - end diff --git a/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref index e0fffd99e5..cd91623c5d 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref @@ -268,17 +268,3 @@ let _ = a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond - then x - else - begin match e with - | A -> - function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> - b - end diff --git a/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref index 75e34eafb5..fcd8a67fda 100644 --- a/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref @@ -227,16 +227,3 @@ let _ = else (* a comment *) match e with A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then x - else - begin match e with - | A -> - function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> - b - end diff --git a/test/passing/refs.ocamlformat/ite-vertical.ml.err b/test/passing/refs.ocamlformat/ite-vertical.ml.err index 94ff935b4d..6d93e7b45d 100644 --- a/test/passing/refs.ocamlformat/ite-vertical.ml.err +++ b/test/passing/refs.ocamlformat/ite-vertical.ml.err @@ -1,2 +1,2 @@ Warning: ite-vertical.ml:291 exceeds the margin -Warning: ite-vertical.ml:302 exceeds the margin +Warning: ite-vertical.ml:304 exceeds the margin diff --git a/test/passing/refs.ocamlformat/ite-vertical.ml.ref b/test/passing/refs.ocamlformat/ite-vertical.ml.ref index 6856d08a9f..eec3519ff7 100644 --- a/test/passing/refs.ocamlformat/ite-vertical.ml.ref +++ b/test/passing/refs.ocamlformat/ite-vertical.ml.ref @@ -290,7 +290,9 @@ let f = | A -> if gf then (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then + begin if + a + then b end @@ -329,17 +331,3 @@ let _ = a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then - x - else - begin match e with - | A -> - function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> - b - end diff --git a/test/passing/refs.ocamlformat/ite.ml.ref b/test/passing/refs.ocamlformat/ite.ml.ref index 5687e9ada6..83155c2a00 100644 --- a/test/passing/refs.ocamlformat/ite.ml.ref +++ b/test/passing/refs.ocamlformat/ite.ml.ref @@ -230,16 +230,3 @@ let _ = else (* a comment *) match e with A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then x - else - begin match e with - | A -> - function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> - b - end diff --git a/test/passing/tests/ite.ml b/test/passing/tests/ite.ml index 71796f892e..7e478ce9a5 100644 --- a/test/passing/tests/ite.ml +++ b/test/passing/tests/ite.ml @@ -237,14 +237,3 @@ let _ = match e with | A -> a | B -> b - -(* A bare [begin match ... end] branch must keep [match ... with] on one line, - not split it as [begin match] / scrutinee / [with], and must align [end] - with [begin] (regression test) *) -let _ = - if cond then x - else begin - match e with - | A -> function_with_a_long_enough_name_to_force_a_vertical_break a - | B -> b - end From be77c0151198ac56a6bc7efbfe17b995d58832a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Wed, 24 Jun 2026 16:04:42 +0200 Subject: [PATCH 5/7] Rework begin match/if branch layout (review follow-up) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reworks the previous fix (e3babbb1) per review. The earlier version special-cased `ctx0=ifthenelse` in `fmt_beginend` to handle a comment before a `begin match/if … end` branch body; it glued the body (`begin if a then b`) and reindented it when a comment was added. Why the comment case now goes through the plain begin/end path: `fmt_beginend` cannot see the comment — `branch_pro` consumes it in `Params` before the expression is formatted. `get_if_then_else`, however, runs before consumption, so the decision belongs there. A special `begin match/if … end` branch with a leading comment on its body no longer takes the `begin ` shortcut arm; it falls through to the existing plain begin/end machinery (`has_cmts_before` predicate). That keeps `begin` on its own line with the body (comment included) one indent in, identically across all if-then-else modes, so adding a comment no longer reindents the body. Why expr_pro is dropped for special-bodied begin/end branches: the fit-or-vertical / vertical branch `expr_pro` is `break_unless_newline 1000`, which enqueues width 1000 even as a no-op at BOL and poisons the body's `match … with` / `if … then` header box, forcing it to split over several lines. Such a body already breaks after `begin`, so it provides its own break instead of the poisoning one. Simple-bodied `begin e end` keeps the regular branch break (no header to poison). K&R additionally dropped the extra body box that indented a comment-routed body by +2. Why a ctx0 box wrap remains in fmt_beginend: the no-comment shortcut path still needs `end` aligned with `begin`. In fit-or-vertical the branch box is `hovbox 0` while the branch break indents `begin` one level in, so the body and `end` are wrapped together. This is scoped to `ctx0=ifthenelse` because wrapping unconditionally reindents application arguments (`map x begin fun … end`, exp_grouping.ml); the scope is structural (alignment), not comment-handling logic. Co-Authored-By: Claude Opus 4.8 (1M context) --- CHANGES.md | 7 +++ lib/Fmt_ast.ml | 23 ++++++++-- lib/Params.ml | 46 ++++++++++++++----- lib/Params.mli | 1 + test/passing/refs.ahrefs/ite-compact.ml.ref | 17 +++++-- .../refs.ahrefs/ite-compact_closing.ml.ref | 17 +++++-- .../refs.ahrefs/ite-fit_or_vertical.ml.err | 2 +- .../refs.ahrefs/ite-fit_or_vertical.ml.ref | 19 ++++++-- .../ite-fit_or_vertical_closing.ml.err | 2 +- .../ite-fit_or_vertical_closing.ml.ref | 19 ++++++-- .../ite-fit_or_vertical_no_indicate.ml.err | 2 +- .../ite-fit_or_vertical_no_indicate.ml.ref | 19 ++++++-- test/passing/refs.ahrefs/ite-kr.ml.ref | 16 ++++++- .../passing/refs.ahrefs/ite-kr_closing.ml.ref | 16 ++++++- test/passing/refs.ahrefs/ite-kw_first.ml.ref | 18 ++++++-- .../refs.ahrefs/ite-kw_first_closing.ml.ref | 18 ++++++-- .../ite-kw_first_no_indicate.ml.ref | 18 ++++++-- .../refs.ahrefs/ite-no_indicate.ml.ref | 17 +++++-- test/passing/refs.ahrefs/ite-vertical.ml.err | 2 +- test/passing/refs.ahrefs/ite-vertical.ml.ref | 20 ++++++-- test/passing/refs.ahrefs/ite.ml.ref | 17 +++++-- test/passing/refs.default/ite-compact.ml.ref | 17 +++++-- .../refs.default/ite-compact_closing.ml.ref | 17 +++++-- .../refs.default/ite-fit_or_vertical.ml.err | 2 +- .../refs.default/ite-fit_or_vertical.ml.ref | 19 ++++++-- .../ite-fit_or_vertical_closing.ml.err | 2 +- .../ite-fit_or_vertical_closing.ml.ref | 19 ++++++-- .../ite-fit_or_vertical_no_indicate.ml.err | 2 +- .../ite-fit_or_vertical_no_indicate.ml.ref | 19 ++++++-- test/passing/refs.default/ite-kr.ml.ref | 16 ++++++- .../refs.default/ite-kr_closing.ml.ref | 16 ++++++- test/passing/refs.default/ite-kw_first.ml.ref | 18 ++++++-- .../refs.default/ite-kw_first_closing.ml.ref | 18 ++++++-- .../ite-kw_first_no_indicate.ml.ref | 18 ++++++-- .../refs.default/ite-no_indicate.ml.ref | 17 +++++-- test/passing/refs.default/ite-vertical.ml.err | 2 +- test/passing/refs.default/ite-vertical.ml.ref | 20 ++++++-- test/passing/refs.default/ite.ml.ref | 17 +++++-- .../refs.janestreet/ite-compact.ml.ref | 11 +++++ .../ite-compact_closing.ml.ref | 12 +++++ .../ite-fit_or_vertical.ml.ref | 12 +++++ .../ite-fit_or_vertical_closing.ml.ref | 13 ++++++ .../ite-fit_or_vertical_no_indicate.ml.ref | 12 +++++ test/passing/refs.janestreet/ite-kr.ml.ref | 13 ++++++ .../refs.janestreet/ite-kr_closing.ml.ref | 13 ++++++ .../refs.janestreet/ite-kw_first.ml.ref | 12 +++++ .../ite-kw_first_closing.ml.ref | 13 ++++++ .../ite-kw_first_no_indicate.ml.ref | 12 +++++ .../refs.janestreet/ite-no_indicate.ml.ref | 11 +++++ .../refs.janestreet/ite-vertical.ml.ref | 12 +++++ test/passing/refs.janestreet/ite.ml.ref | 11 +++++ .../refs.ocamlformat/ite-compact.ml.ref | 19 ++++++-- .../ite-compact_closing.ml.ref | 19 ++++++-- .../ite-fit_or_vertical.ml.err | 2 +- .../ite-fit_or_vertical.ml.ref | 21 +++++++-- .../ite-fit_or_vertical_closing.ml.err | 2 +- .../ite-fit_or_vertical_closing.ml.ref | 21 +++++++-- .../ite-fit_or_vertical_no_indicate.ml.err | 2 +- .../ite-fit_or_vertical_no_indicate.ml.ref | 21 +++++++-- test/passing/refs.ocamlformat/ite-kr.ml.ref | 18 +++++++- .../refs.ocamlformat/ite-kr_closing.ml.ref | 18 +++++++- .../refs.ocamlformat/ite-kw_first.ml.ref | 20 ++++++-- .../ite-kw_first_closing.ml.ref | 20 ++++++-- .../ite-kw_first_no_indicate.ml.ref | 20 ++++++-- .../refs.ocamlformat/ite-no_indicate.ml.ref | 19 ++++++-- .../refs.ocamlformat/ite-vertical.ml.err | 2 +- .../refs.ocamlformat/ite-vertical.ml.ref | 22 +++++++-- test/passing/refs.ocamlformat/ite.ml.ref | 19 ++++++-- test/passing/tests/ite.ml | 11 +++++ 69 files changed, 825 insertions(+), 163 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b72c1fcfd1..30269a36cd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,13 @@ profile. This started with version 0.26.0. ### Fixed +- Fix `begin match … end` (and `begin if … end`) branches: with + `if-then-else=fit-or-vertical` the `match … with` header no longer splits + over several lines and `end` is aligned with `begin`; and a leading comment + on the body no longer reindents it — `begin` keeps the body one indent in + instead of gluing the keyword to the comment. + (#2810, @MisterDA) + - Fix indentation of a bare `match`/`function`/`try` branch preceded by a comment with `if-then-else=fit-or-vertical`: the branch is no longer indented relative to the comment's end column. diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index a4c8cb21db..80b2144153 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -2581,6 +2581,7 @@ and fmt_expression c ?(box = true) ?(pro = noop) ?eol ?parens in let p = Params.get_if_then_else c.conf ~cmts_before_opt + ~has_cmts_before:(Cmts.has_before c.cmts) ~pro:(fmt_if first pro_inner) ~first ~last ~parens_bch ~parens_prev_bch:!parens_prev_bch ~xcond ~xbch ~expr_loc:pexp_loc @@ -3039,11 +3040,23 @@ and fmt_beginend c ~loc ?(box = true) ?(pro = noop) ~ctx ~ctx0 ~fmt_atrs $ match e.pexp_desc with | Pexp_match _ | Pexp_try _ | Pexp_function _ | Pexp_ifthenelse _ -> - beginend_box - (fmt_expression c - ~pro:(pro $ begin_ $ str " ") - ~box:false ?eol ~parens:false ~indent_wrap (sub_exp ~ctx e) ) - $ end_ + (* In an [if-then-else] branch the branch break indents [begin] one + level in (e.g. [fit-or-vertical], whose branch box is [hovbox 0]), + while [end] follows the branch box; wrap the body and [end] together + so [end] lines up with [begin]. Other contexts (e.g. [map x begin + fun … end] as an application argument) must keep their own + indentation. *) + let box = + match ctx0 with + | Exp {pexp_desc= Pexp_ifthenelse _; _} -> hvbox 0 + | _ -> Fn.id + in + box + ( beginend_box + (fmt_expression c + ~pro:(pro $ begin_ $ str " ") + ~box:false ?eol ~parens:false ~indent_wrap (sub_exp ~ctx e) ) + $ end_ ) | _ -> beginend_box ( hvbox 0 (pro $ begin_) diff --git a/lib/Params.ml b/lib/Params.ml index c3800d43a9..2d69f28b5a 100644 --- a/lib/Params.ml +++ b/lib/Params.ml @@ -871,15 +871,22 @@ type if_then_else = ; break_end_branch: Fmt.t ; space_between_branches: Fmt.t } -let get_if_then_else (c : Conf.t) ~cmts_before_opt ~pro ~first ~last - ~parens_bch ~parens_prev_bch ~xcond ~xbch ~expr_loc ~fmt_infix_ext_attrs - ~infix_ext_attrs ~fmt_cond ~cmts_before_kw ~cmts_after_kw = +let get_if_then_else (c : Conf.t) ~cmts_before_opt ~has_cmts_before ~pro + ~first ~last ~parens_bch ~parens_prev_bch ~xcond ~xbch ~expr_loc + ~fmt_infix_ext_attrs ~infix_ext_attrs ~fmt_cond ~cmts_before_kw + ~cmts_after_kw = let imd = c.fmt_opts.indicate_multiline_delimiters.v in let beginend_loc, infix_ext_attrs_beginend, branch_expr = let ast = xbch.Ast.ast in match ast with - | {pexp_desc= Pexp_beginend ({pexp_desc; _}, _); _} - when is_special_beginend pexp_desc -> + | {pexp_desc= Pexp_beginend (nested_exp, _); _} + when is_special_beginend nested_exp.pexp_desc + && not (has_cmts_before nested_exp.pexp_loc) -> + (* [begin match/try/function/if … end] shortcut: keep [begin] glued + to the body keyword. A leading comment on the body breaks the + glue, so fall through to the plain [begin]/[end] machinery below, + which puts [begin] on its own line and the body (comment included) + one indent in. *) (None, None, xbch) | { pexp_desc= Pexp_beginend (nested_exp, infix_ext_attrs) ; pexp_attributes= [] @@ -891,6 +898,18 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~pro ~first ~last | _ -> (None, None, xbch) in let has_beginend = Option.is_some beginend_loc in + (* A [begin]/[end] branch whose body is a [match]/[try]/[function]/[if] + (the [begin match … end] shortcut, or its plain form when a leading + comment de-glues [begin] from the body). Such a body has a header + ([match … with], [if … then]) that the branch [break_unless_newline + 1000] would wrongly split, so it provides its own break after [begin] + instead. Simple-bodied [begin … end] keeps the regular branch break. *) + let is_special_beginend_branch = + match xbch.ast.pexp_desc with + | Pexp_beginend (nested_exp, _) -> + is_special_beginend nested_exp.pexp_desc + | _ -> false + in let bare_branch = is_bare_branch ~parens_bch xbch.ast.pexp_desc in let wrap_parens ~wrap_breaks k = if has_beginend then @@ -996,7 +1015,7 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~pro ~first ~last ; branch_pro= branch_pro ~begin_end_offset:0 () ; wrap_parens= wrap_parens ~wrap_breaks:(wrap (break 1000 2) noop) ; beginend_loc - ; box_expr= Some has_beginend + ; box_expr= Some (has_beginend && not is_special_beginend_branch) ; expr_pro= None ; expr_eol= Some (break 1 2) ; branch_expr @@ -1024,10 +1043,13 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~pro ~first ~last ; beginend_loc ; box_expr= Some false ; expr_pro= - Some - (fmt_if - (not (Location.is_single_line expr_loc c.fmt_opts.margin.v)) - (break_unless_newline 1000 2) ) + ( if is_special_beginend_branch then None + else + Some + (fmt_if + (not + (Location.is_single_line expr_loc c.fmt_opts.margin.v) ) + (break_unless_newline 1000 2) ) ) ; expr_eol= Some (break 1 2) ; branch_expr ; break_end_branch= noop @@ -1048,7 +1070,9 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~pro ~first ~last ~cls_hint:((1, 0), (1000, 0)) ) ; beginend_loc ; box_expr= None - ; expr_pro= Some (break_unless_newline 1000 2) + ; expr_pro= + ( if is_special_beginend_branch then None + else Some (break_unless_newline 1000 2) ) ; expr_eol= None ; branch_expr ; break_end_branch= noop diff --git a/lib/Params.mli b/lib/Params.mli index c1c5531d22..b9d270bc63 100644 --- a/lib/Params.mli +++ b/lib/Params.mli @@ -221,6 +221,7 @@ type if_then_else = val get_if_then_else : Conf.t -> cmts_before_opt:(Location.t -> Fmt.t option) + -> has_cmts_before:(Location.t -> bool) -> pro:Fmt.t -> first:bool -> last:bool diff --git a/test/passing/refs.ahrefs/ite-compact.ml.ref b/test/passing/refs.ahrefs/ite-compact.ml.ref index 5cecf62364..f44cf85017 100644 --- a/test/passing/refs.ahrefs/ite-compact.ml.ref +++ b/test/passing/refs.ahrefs/ite-compact.ml.ref @@ -207,10 +207,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -240,3 +240,14 @@ let _ = match e with | A -> a | B -> b) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-compact_closing.ml.ref b/test/passing/refs.ahrefs/ite-compact_closing.ml.ref index afecf296ca..4a0d1b6905 100644 --- a/test/passing/refs.ahrefs/ite-compact_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-compact_closing.ml.ref @@ -226,10 +226,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -261,3 +261,14 @@ let _ = | A -> a | B -> b ) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.err b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.err index fc51770a03..c19dc1cebd 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.err +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical.ml:116 exceeds the margin Warning: ite-fit_or_vertical.ml:121 exceeds the margin Warning: ite-fit_or_vertical.ml:126 exceeds the margin Warning: ite-fit_or_vertical.ml:247 exceeds the margin -Warning: ite-fit_or_vertical.ml:260 exceeds the margin +Warning: ite-fit_or_vertical.ml:257 exceeds the margin diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref index 588060ddaa..8de6888f59 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref @@ -244,12 +244,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -284,3 +281,15 @@ let _ = match e with | A -> a | B -> b) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.err b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.err index 5fedffb9e3..357f0a1a12 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.err +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.err @@ -1,2 +1,2 @@ Warning: ite-fit_or_vertical_closing.ml:257 exceeds the margin -Warning: ite-fit_or_vertical_closing.ml:270 exceeds the margin +Warning: ite-fit_or_vertical_closing.ml:267 exceeds the margin diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref index dda0cc0440..eab77faebe 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref @@ -254,12 +254,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -296,3 +293,15 @@ let _ = | A -> a | B -> b ) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.err b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.err index 9eff570afe..7a8b20a690 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.err +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical_no_indicate.ml:116 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:121 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:126 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:247 exceeds the margin -Warning: ite-fit_or_vertical_no_indicate.ml:260 exceeds the margin +Warning: ite-fit_or_vertical_no_indicate.ml:257 exceeds the margin diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref index 588060ddaa..8de6888f59 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref @@ -244,12 +244,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -284,3 +281,15 @@ let _ = match e with | A -> a | B -> b) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-kr.ml.ref b/test/passing/refs.ahrefs/ite-kr.ml.ref index 073ec2f740..ee12580364 100644 --- a/test/passing/refs.ahrefs/ite-kr.ml.ref +++ b/test/passing/refs.ahrefs/ite-kr.ml.ref @@ -283,9 +283,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b + if a then b end (* Long comment before match in else branch (regression test for @@ -322,3 +322,15 @@ let _ = | A -> a | B -> b ) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-kr_closing.ml.ref b/test/passing/refs.ahrefs/ite-kr_closing.ml.ref index 7162d363d9..dc29beba54 100644 --- a/test/passing/refs.ahrefs/ite-kr_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-kr_closing.ml.ref @@ -290,9 +290,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b + if a then b end (* Long comment before match in else branch (regression test for @@ -329,3 +329,15 @@ let _ = | A -> a | B -> b ) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-kw_first.ml.ref b/test/passing/refs.ahrefs/ite-kw_first.ml.ref index 572b9ec54d..dd70adb89b 100644 --- a/test/passing/refs.ahrefs/ite-kw_first.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first.ml.ref @@ -239,10 +239,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -276,3 +276,15 @@ let _ = match e with | A -> a | B -> b) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref b/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref index 90ba78b33e..1b5d18b7a2 100644 --- a/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref @@ -258,10 +258,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -297,3 +297,15 @@ let _ = | A -> a | B -> b ) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref index 572b9ec54d..dd70adb89b 100644 --- a/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref @@ -239,10 +239,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -276,3 +276,15 @@ let _ = match e with | A -> a | B -> b) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-no_indicate.ml.ref index 5cecf62364..f44cf85017 100644 --- a/test/passing/refs.ahrefs/ite-no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-no_indicate.ml.ref @@ -207,10 +207,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -240,3 +240,14 @@ let _ = match e with | A -> a | B -> b) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite-vertical.ml.err b/test/passing/refs.ahrefs/ite-vertical.ml.err index b2aa89ed3a..9e3cea0178 100644 --- a/test/passing/refs.ahrefs/ite-vertical.ml.err +++ b/test/passing/refs.ahrefs/ite-vertical.ml.err @@ -2,4 +2,4 @@ Warning: ite-vertical.ml:131 exceeds the margin Warning: ite-vertical.ml:136 exceeds the margin Warning: ite-vertical.ml:141 exceeds the margin Warning: ite-vertical.ml:284 exceeds the margin -Warning: ite-vertical.ml:297 exceeds the margin +Warning: ite-vertical.ml:295 exceeds the margin diff --git a/test/passing/refs.ahrefs/ite-vertical.ml.ref b/test/passing/refs.ahrefs/ite-vertical.ml.ref index 57f3f40112..0d1facddd2 100644 --- a/test/passing/refs.ahrefs/ite-vertical.ml.ref +++ b/test/passing/refs.ahrefs/ite-vertical.ml.ref @@ -281,13 +281,11 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then + if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -321,3 +319,15 @@ let _ = match e with | A -> a | B -> b) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.ahrefs/ite.ml.ref b/test/passing/refs.ahrefs/ite.ml.ref index 5cecf62364..f44cf85017 100644 --- a/test/passing/refs.ahrefs/ite.ml.ref +++ b/test/passing/refs.ahrefs/ite.ml.ref @@ -207,10 +207,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -240,3 +240,14 @@ let _ = match e with | A -> a | B -> b) + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-compact.ml.ref b/test/passing/refs.default/ite-compact.ml.ref index 2bb4a004b3..df0da3bd91 100644 --- a/test/passing/refs.default/ite-compact.ml.ref +++ b/test/passing/refs.default/ite-compact.ml.ref @@ -201,10 +201,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -231,3 +231,14 @@ let _ = else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-compact_closing.ml.ref b/test/passing/refs.default/ite-compact_closing.ml.ref index a738e1750c..95d3fc81d2 100644 --- a/test/passing/refs.default/ite-compact_closing.ml.ref +++ b/test/passing/refs.default/ite-compact_closing.ml.ref @@ -216,10 +216,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -246,3 +246,14 @@ let _ = else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-fit_or_vertical.ml.err b/test/passing/refs.default/ite-fit_or_vertical.ml.err index 19b7a99c10..6dd85c4c82 100644 --- a/test/passing/refs.default/ite-fit_or_vertical.ml.err +++ b/test/passing/refs.default/ite-fit_or_vertical.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical.ml:115 exceeds the margin Warning: ite-fit_or_vertical.ml:120 exceeds the margin Warning: ite-fit_or_vertical.ml:125 exceeds the margin Warning: ite-fit_or_vertical.ml:247 exceeds the margin -Warning: ite-fit_or_vertical.ml:260 exceeds the margin +Warning: ite-fit_or_vertical.ml:257 exceeds the margin diff --git a/test/passing/refs.default/ite-fit_or_vertical.ml.ref b/test/passing/refs.default/ite-fit_or_vertical.ml.ref index 6823b0ea2b..a53c85526a 100644 --- a/test/passing/refs.default/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical.ml.ref @@ -244,12 +244,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -284,3 +281,15 @@ let _ = match e with | A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.err b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.err index 126313710f..2be0bcc178 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.err +++ b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.err @@ -1,2 +1,2 @@ Warning: ite-fit_or_vertical_closing.ml:256 exceeds the margin -Warning: ite-fit_or_vertical_closing.ml:269 exceeds the margin +Warning: ite-fit_or_vertical_closing.ml:266 exceeds the margin diff --git a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref index 2d41da0941..fadf4b0dac 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref @@ -253,12 +253,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -293,3 +290,15 @@ let _ = match e with | A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.err b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.err index bef0700a1d..3700b779cf 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.err +++ b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical_no_indicate.ml:115 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:120 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:125 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:247 exceeds the margin -Warning: ite-fit_or_vertical_no_indicate.ml:260 exceeds the margin +Warning: ite-fit_or_vertical_no_indicate.ml:257 exceeds the margin diff --git a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref index 6823b0ea2b..a53c85526a 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref @@ -244,12 +244,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -284,3 +281,15 @@ let _ = match e with | A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-kr.ml.ref b/test/passing/refs.default/ite-kr.ml.ref index 18e5097328..c8a446a7c5 100644 --- a/test/passing/refs.default/ite-kr.ml.ref +++ b/test/passing/refs.default/ite-kr.ml.ref @@ -280,9 +280,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b + if a then b end (* Long comment before match in else branch (regression test for @@ -314,3 +314,15 @@ let _ = x else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-kr_closing.ml.ref b/test/passing/refs.default/ite-kr_closing.ml.ref index 5a25615277..040f27eb2d 100644 --- a/test/passing/refs.default/ite-kr_closing.ml.ref +++ b/test/passing/refs.default/ite-kr_closing.ml.ref @@ -287,9 +287,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b + if a then b end (* Long comment before match in else branch (regression test for @@ -321,3 +321,15 @@ let _ = x else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-kw_first.ml.ref b/test/passing/refs.default/ite-kw_first.ml.ref index 2ed516f897..d4c9595975 100644 --- a/test/passing/refs.default/ite-kw_first.ml.ref +++ b/test/passing/refs.default/ite-kw_first.ml.ref @@ -233,10 +233,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -270,3 +270,15 @@ let _ = match e with | A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-kw_first_closing.ml.ref b/test/passing/refs.default/ite-kw_first_closing.ml.ref index e1aa0f329d..76186d0795 100644 --- a/test/passing/refs.default/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.default/ite-kw_first_closing.ml.ref @@ -248,10 +248,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -285,3 +285,15 @@ let _ = match e with | A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref index 2ed516f897..d4c9595975 100644 --- a/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref @@ -233,10 +233,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -270,3 +270,15 @@ let _ = match e with | A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-no_indicate.ml.ref b/test/passing/refs.default/ite-no_indicate.ml.ref index 2bb4a004b3..df0da3bd91 100644 --- a/test/passing/refs.default/ite-no_indicate.ml.ref +++ b/test/passing/refs.default/ite-no_indicate.ml.ref @@ -201,10 +201,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -231,3 +231,14 @@ let _ = else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite-vertical.ml.err b/test/passing/refs.default/ite-vertical.ml.err index 3a6f50f9a7..906b414ced 100644 --- a/test/passing/refs.default/ite-vertical.ml.err +++ b/test/passing/refs.default/ite-vertical.ml.err @@ -2,4 +2,4 @@ Warning: ite-vertical.ml:131 exceeds the margin Warning: ite-vertical.ml:136 exceeds the margin Warning: ite-vertical.ml:141 exceeds the margin Warning: ite-vertical.ml:286 exceeds the margin -Warning: ite-vertical.ml:299 exceeds the margin +Warning: ite-vertical.ml:297 exceeds the margin diff --git a/test/passing/refs.default/ite-vertical.ml.ref b/test/passing/refs.default/ite-vertical.ml.ref index 5c7eb37b9f..299720fb0c 100644 --- a/test/passing/refs.default/ite-vertical.ml.ref +++ b/test/passing/refs.default/ite-vertical.ml.ref @@ -283,13 +283,11 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then + if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -323,3 +321,15 @@ let _ = match e with | A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.default/ite.ml.ref b/test/passing/refs.default/ite.ml.ref index 2bb4a004b3..df0da3bd91 100644 --- a/test/passing/refs.default/ite.ml.ref +++ b/test/passing/refs.default/ite.ml.ref @@ -201,10 +201,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -231,3 +231,14 @@ let _ = else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end diff --git a/test/passing/refs.janestreet/ite-compact.ml.ref b/test/passing/refs.janestreet/ite-compact.ml.ref index c9203b2905..a9bb04fced 100644 --- a/test/passing/refs.janestreet/ite-compact.ml.ref +++ b/test/passing/refs.janestreet/ite-compact.ml.ref @@ -246,3 +246,14 @@ let _ = | A -> a | B -> b) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-compact_closing.ml.ref b/test/passing/refs.janestreet/ite-compact_closing.ml.ref index ea57aa99c5..4c438df481 100644 --- a/test/passing/refs.janestreet/ite-compact_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-compact_closing.ml.ref @@ -262,3 +262,15 @@ let _ = | B -> b ) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref index d2bd3bd125..347d35bb4d 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref @@ -300,3 +300,15 @@ let _ = | A -> a | B -> b) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref index 4ff166ae94..8834bc8e78 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref @@ -313,3 +313,16 @@ let _ = | B -> b ) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref index d2bd3bd125..347d35bb4d 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref @@ -300,3 +300,15 @@ let _ = | A -> a | B -> b) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-kr.ml.ref b/test/passing/refs.janestreet/ite-kr.ml.ref index 29b1c8a72e..8914e9364b 100644 --- a/test/passing/refs.janestreet/ite-kr.ml.ref +++ b/test/passing/refs.janestreet/ite-kr.ml.ref @@ -349,3 +349,16 @@ let _ = | B -> b ) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-kr_closing.ml.ref b/test/passing/refs.janestreet/ite-kr_closing.ml.ref index 8f916d8755..62a53ce1fa 100644 --- a/test/passing/refs.janestreet/ite-kr_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-kr_closing.ml.ref @@ -356,3 +356,16 @@ let _ = | B -> b ) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-kw_first.ml.ref b/test/passing/refs.janestreet/ite-kw_first.ml.ref index 7eccbbf131..676e727232 100644 --- a/test/passing/refs.janestreet/ite-kw_first.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first.ml.ref @@ -281,3 +281,15 @@ let _ = | A -> a | B -> b) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref b/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref index 0b2eea44e3..42bb8cbc7b 100644 --- a/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref @@ -297,3 +297,16 @@ let _ = | B -> b ) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + ) +;; diff --git a/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref index 7eccbbf131..676e727232 100644 --- a/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref @@ -281,3 +281,15 @@ let _ = | A -> a | B -> b) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-no_indicate.ml.ref b/test/passing/refs.janestreet/ite-no_indicate.ml.ref index c9203b2905..a9bb04fced 100644 --- a/test/passing/refs.janestreet/ite-no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-no_indicate.ml.ref @@ -246,3 +246,14 @@ let _ = | A -> a | B -> b) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite-vertical.ml.ref b/test/passing/refs.janestreet/ite-vertical.ml.ref index ca83aeaa78..ed633fe784 100644 --- a/test/passing/refs.janestreet/ite-vertical.ml.ref +++ b/test/passing/refs.janestreet/ite-vertical.ml.ref @@ -345,3 +345,15 @@ let _ = | A -> a | B -> b) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.janestreet/ite.ml.ref b/test/passing/refs.janestreet/ite.ml.ref index c9203b2905..a9bb04fced 100644 --- a/test/passing/refs.janestreet/ite.ml.ref +++ b/test/passing/refs.janestreet/ite.ml.ref @@ -246,3 +246,14 @@ let _ = | A -> a | B -> b) ;; + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else ( + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b) +;; diff --git a/test/passing/refs.ocamlformat/ite-compact.ml.ref b/test/passing/refs.ocamlformat/ite-compact.ml.ref index 83155c2a00..5c1d33eaca 100644 --- a/test/passing/refs.ocamlformat/ite-compact.ml.ref +++ b/test/passing/refs.ocamlformat/ite-compact.ml.ref @@ -200,10 +200,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -230,3 +230,16 @@ let _ = else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref b/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref index 8419952288..9226ebbccb 100644 --- a/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref @@ -210,10 +210,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -240,3 +240,16 @@ let _ = else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.err b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.err index 35c4dd8d0a..65da7bfbf6 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.err +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.err @@ -1,2 +1,2 @@ Warning: ite-fit_or_vertical.ml:250 exceeds the margin -Warning: ite-fit_or_vertical.ml:263 exceeds the margin +Warning: ite-fit_or_vertical.ml:260 exceeds the margin diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref index 7893174529..c7bb0c0543 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref @@ -247,12 +247,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -290,3 +287,17 @@ let _ = a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.err b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.err index 23c64dbaf7..7fd8ac1f7b 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.err +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.err @@ -1,2 +1,2 @@ Warning: ite-fit_or_vertical_closing.ml:255 exceeds the margin -Warning: ite-fit_or_vertical_closing.ml:268 exceeds the margin +Warning: ite-fit_or_vertical_closing.ml:265 exceeds the margin diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref index 3a55cb14ea..19b6ca204a 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref @@ -252,12 +252,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -295,3 +292,17 @@ let _ = a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.err b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.err index 0ef658ec2b..55504ff751 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.err +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.err @@ -2,4 +2,4 @@ Warning: ite-fit_or_vertical_no_indicate.ml:110 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:115 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:120 exceeds the margin Warning: ite-fit_or_vertical_no_indicate.ml:247 exceeds the margin -Warning: ite-fit_or_vertical_no_indicate.ml:260 exceeds the margin +Warning: ite-fit_or_vertical_no_indicate.ml:257 exceeds the margin diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref index 3fcdd46a97..3535e98ef6 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref @@ -244,12 +244,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then - b + if a then b end (* Long comment before match in else branch (regression test for @@ -287,3 +284,17 @@ let _ = a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-kr.ml.ref b/test/passing/refs.ocamlformat/ite-kr.ml.ref index eeb42049d5..06edf9e8d6 100644 --- a/test/passing/refs.ocamlformat/ite-kr.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kr.ml.ref @@ -281,9 +281,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b + if a then b end (* Long comment before match in else branch (regression test for @@ -316,3 +316,17 @@ let _ = x else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref b/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref index 698fa891f1..0c652349bd 100644 --- a/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref @@ -285,9 +285,9 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b + if a then b end (* Long comment before match in else branch (regression test for @@ -320,3 +320,17 @@ let _ = x else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-kw_first.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first.ml.ref index e84a2754f5..a528e27e79 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first.ml.ref @@ -231,10 +231,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -271,3 +271,17 @@ let _ = a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref index a530a75e19..57e731abbf 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref @@ -241,10 +241,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -281,3 +281,17 @@ let _ = a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref index cd91623c5d..5ae17c4ef6 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref @@ -228,10 +228,10 @@ let f = match x with | A -> if gf - then + then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -268,3 +268,17 @@ let _ = a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond + then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref index fcd8a67fda..23c01681ba 100644 --- a/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref @@ -197,10 +197,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -227,3 +227,16 @@ let _ = else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite-vertical.ml.err b/test/passing/refs.ocamlformat/ite-vertical.ml.err index 6d93e7b45d..94ff935b4d 100644 --- a/test/passing/refs.ocamlformat/ite-vertical.ml.err +++ b/test/passing/refs.ocamlformat/ite-vertical.ml.err @@ -1,2 +1,2 @@ Warning: ite-vertical.ml:291 exceeds the margin -Warning: ite-vertical.ml:304 exceeds the margin +Warning: ite-vertical.ml:302 exceeds the margin diff --git a/test/passing/refs.ocamlformat/ite-vertical.ml.ref b/test/passing/refs.ocamlformat/ite-vertical.ml.ref index eec3519ff7..9d4e4ff10f 100644 --- a/test/passing/refs.ocamlformat/ite-vertical.ml.ref +++ b/test/passing/refs.ocamlformat/ite-vertical.ml.ref @@ -288,13 +288,11 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if - a - then + if a then b - end + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -331,3 +329,17 @@ let _ = a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then + x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/refs.ocamlformat/ite.ml.ref b/test/passing/refs.ocamlformat/ite.ml.ref index 83155c2a00..5c1d33eaca 100644 --- a/test/passing/refs.ocamlformat/ite.ml.ref +++ b/test/passing/refs.ocamlformat/ite.ml.ref @@ -200,10 +200,10 @@ let test = let f = match x with | A -> - if gf then + if gf then begin (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) - begin if a then b - end + if a then b + end (* Long comment before match in else branch (regression test for formatting oscillation) *) @@ -230,3 +230,16 @@ let _ = else (* a comment *) match e with A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else + begin match e with + | A -> + function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> + b + end diff --git a/test/passing/tests/ite.ml b/test/passing/tests/ite.ml index 7e478ce9a5..71796f892e 100644 --- a/test/passing/tests/ite.ml +++ b/test/passing/tests/ite.ml @@ -237,3 +237,14 @@ let _ = match e with | A -> a | B -> b + +(* A bare [begin match ... end] branch must keep [match ... with] on one line, + not split it as [begin match] / scrutinee / [with], and must align [end] + with [begin] (regression test) *) +let _ = + if cond then x + else begin + match e with + | A -> function_with_a_long_enough_name_to_force_a_vertical_break a + | B -> b + end From 9ddccfbd21d845d2d5e0ec9c373edaf50b240edf Mon Sep 17 00:00:00 2001 From: Boris Yakobowski Date: Mon, 6 Jul 2026 20:23:37 +0100 Subject: [PATCH 6/7] Fix comment-before-paren gluing in fit-or-vertical ITE branches When a comment precedes a parenthesized match/try/function/if branch (janestreet and ahrefs profiles with parens_ite or exp_grouping=parens), glue the opening paren to the content instead of putting it alone on a line. Before: `(* cmt *)\n(\nmatch e with\n| ...)` After: `(* cmt *)\n(match e with\n | ...)` Also simplify raw_cmts_branch_pro: remove the bare_branch distinction (always emit trailing break), since paren-glue now handles the case that bare_branch was partially covering. Co-Authored-By: Claude Opus 4.6 --- lib/Fmt_ast.ml | 20 +++-- lib/Params.ml | 81 ++++++++++--------- lib/Params.mli | 12 +-- .../refs.ahrefs/ite-fit_or_vertical.ml.ref | 14 ++-- .../ite-fit_or_vertical_closing.ml.ref | 14 ++-- .../ite-fit_or_vertical_no_indicate.ml.ref | 14 ++-- .../ite-fit_or_vertical.ml.ref | 14 ++-- .../ite-fit_or_vertical_closing.ml.ref | 14 ++-- .../ite-fit_or_vertical_no_indicate.ml.ref | 14 ++-- 9 files changed, 100 insertions(+), 97 deletions(-) diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index 80b2144153..83c39cfebf 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -2591,16 +2591,20 @@ and fmt_expression c ?(box = true) ?(pro = noop) ?eol ?parens ~fmt_cond:(fmt_expression ~box:false c) ~cmts_before_kw ~cmts_after_kw in - let branch_pro = + let branch_pro, wrap_parens = match raw_cmts_after_kw with | Some cmts -> - let bare_branch = - Params.is_bare_branch ~parens_bch - xbch.ast.pexp_desc + let bp = + Params.raw_cmts_branch_pro c.conf cmts in - Params.raw_cmts_branch_pro ~bare_branch c.conf - cmts - | None -> p.branch_pro + if + parens_bch + && Params + .is_special_or_nested_special_beginend + xbch.ast.pexp_desc + then (bp $ str "(", fun k -> k $ str ")") + else (bp, p.wrap_parens) + | None -> (p.branch_pro, p.wrap_parens) in let wrap_beginend = match p.beginend_loc with @@ -2613,7 +2617,7 @@ and fmt_expression c ?(box = true) ?(pro = noop) ?eol ?parens $ p.box_keyword_and_expr ( branch_pro $ wrap_beginend - (p.wrap_parens + (wrap_parens ( fmt_expression c ?box:p.box_expr ~parens:false ?pro:p.expr_pro ?eol:p.expr_eol p.branch_expr diff --git a/lib/Params.ml b/lib/Params.ml index 2d69f28b5a..cce61575c5 100644 --- a/lib/Params.ml +++ b/lib/Params.ml @@ -516,23 +516,10 @@ let is_special_or_nested_special_beginend = function | Pexp_beginend ({pexp_desc; _}, _) -> is_special_beginend pexp_desc | exp -> is_special_beginend exp -(* An if-then-else branch is rendered "bare" when it is neither wrapped in - [begin]/[end] (including the [begin match end] shortcut, a - [Pexp_beginend]) nor parenthesized. *) -let is_bare_branch ~parens_bch desc = - (not parens_bch) && match desc with Pexp_beginend _ -> false | _ -> true - -let raw_cmts_branch_pro ?(bare_branch = false) (c : Conf.t) cmts = +let raw_cmts_branch_pro (c : Conf.t) cmts = match c.fmt_opts.if_then_else.v with | `Compact -> break 1000 0 $ cmts $ break 1000 0 - (* A bare [match]/[function]/[try]/[if] branch breaks before its own body - with a [break_unless_newline], which is a no-op unless we are already at - the beginning of a line; without a trailing break here the branch box - would open at the comment's end column and indent the body relative to - it. A [begin]/[end]- or paren-wrapped branch instead emits its opening - delimiter right after the comment, so we leave the break to it. *) - | _ when bare_branch -> break 1000 2 $ cmts $ break 1000 2 - | _ -> break 1000 2 $ cmts + | _ -> break 1000 2 $ cmts $ break 1000 2 type cases = { leading_space: Fmt.t @@ -910,7 +897,6 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~has_cmts_before ~pro is_special_beginend nested_exp.pexp_desc | _ -> false in - let bare_branch = is_bare_branch ~parens_bch xbch.ast.pexp_desc in let wrap_parens ~wrap_breaks k = if has_beginend then let infix_ext_attrs_beginend = @@ -967,7 +953,9 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~has_cmts_before ~pro wrapping one), emit it from [branch_pro] with forced breaks, so the branch indentation stays stable regardless of where the comment was initially attached. [default] is the comment-less [branch_pro] for the - current mode, [guard] an extra mode-specific applicability condition. *) + current mode, [guard] an extra mode-specific applicability condition. + Returns [(branch_pro, has_cmts_before)] where [has_cmts_before] is true + when a comment was consumed into [branch_pro]. *) let branch_pro_with_cmts ~default ~guard = if (not has_beginend) @@ -975,27 +963,29 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~has_cmts_before ~pro && (not has_cmts_after_kw) && guard then match cmts_before_opt xbch.ast.pexp_loc with - | Some cmts -> raw_cmts_branch_pro ~bare_branch c cmts + | Some cmts -> (raw_cmts_branch_pro c cmts, true) | None -> ( match xbch.ast.pexp_desc with | Pexp_beginend ({pexp_loc; pexp_desc; _}, _) when is_special_beginend pexp_desc -> ( match cmts_before_opt pexp_loc with - | Some cmts -> raw_cmts_branch_pro ~bare_branch c cmts - | None -> default ) - | _ -> default ) - else default + | Some cmts -> (raw_cmts_branch_pro c cmts, true) + | None -> (default, false) ) + | _ -> (default, false) ) + else (default, false) in match c.fmt_opts.if_then_else.v with | `Compact -> + let branch_pro, _has_cmts = + branch_pro_with_cmts ~default:(branch_pro ~indent:0 ()) + ~guard: + ( (not parens_bch) + && is_special_or_nested_special_beginend xbch.ast.pexp_desc ) + in { box_branch= hovbox ~name:"Params.get_if_then_else `Compact" 2 ; cond= cond () ; box_keyword_and_expr= Fn.id - ; branch_pro= - branch_pro_with_cmts ~default:(branch_pro ~indent:0 ()) - ~guard: - ( (not parens_bch) - && is_special_or_nested_special_beginend xbch.ast.pexp_desc ) + ; branch_pro ; wrap_parens= wrap_parens ~wrap_breaks: @@ -1024,6 +1014,30 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~has_cmts_before ~pro ; space_between_branches= fmt_if (has_beginend || parens_bch) (str " ") } | `Fit_or_vertical -> + let branch_pro_default, has_cmts = + branch_pro_with_cmts + ~default:(branch_pro ~begin_end_offset:0 ()) + ~guard:true + in + let paren_glue = + has_cmts && parens_bch + && is_special_or_nested_special_beginend xbch.ast.pexp_desc + in + let branch_pro, wrap_parens = + if paren_glue then + let cls = + match imd with + | `Closing_on_separate_line -> break 1000 0 $ str ")" + | _ -> str ")" + in + (branch_pro_default $ str "(", fun k -> k $ cls) + else + ( branch_pro_default + , wrap_parens + ~wrap_breaks: + (get_parens_breaks ~opn_hint_indent:2 + ~cls_hint:((1, 0), (1000, 0)) ) ) + in { box_branch= hovbox ( match imd with @@ -1031,19 +1045,12 @@ let get_if_then_else (c : Conf.t) ~cmts_before_opt ~has_cmts_before ~pro | _ -> 0 ) ; cond= cond () ; box_keyword_and_expr= Fn.id - ; branch_pro= - branch_pro_with_cmts - ~default:(branch_pro ~begin_end_offset:0 ()) - ~guard:true - ; wrap_parens= - wrap_parens - ~wrap_breaks: - (get_parens_breaks ~opn_hint_indent:2 - ~cls_hint:((1, 0), (1000, 0)) ) + ; branch_pro + ; wrap_parens ; beginend_loc ; box_expr= Some false ; expr_pro= - ( if is_special_beginend_branch then None + ( if is_special_beginend_branch || paren_glue then None else Some (fmt_if diff --git a/lib/Params.mli b/lib/Params.mli index b9d270bc63..6c3ec7fb1b 100644 --- a/lib/Params.mli +++ b/lib/Params.mli @@ -243,18 +243,10 @@ val is_special_or_nested_special_beginend : expression_desc -> bool the keyword should be extracted without breaks (raw) to prevent oscillation between "after keyword" and "before expression" placements. *) -val is_bare_branch : parens_bch:bool -> expression_desc -> bool -(** [is_bare_branch ~parens_bch desc] is whether an if-then-else branch with - expression description [desc] is rendered "bare", i.e. neither wrapped in - [begin]/[end] (including the [begin match end] shortcut) nor parenthesized. *) - -val raw_cmts_branch_pro : ?bare_branch:bool -> Conf.t -> Fmt.t -> Fmt.t +val raw_cmts_branch_pro : Conf.t -> Fmt.t -> Fmt.t (** [raw_cmts_branch_pro c cmts] returns the branch_pro for raw comments extracted after a keyword, using the correct indentation for the current - if-then-else mode. [bare_branch] (default [false]) indicates the branch is - a bare [match]/[function]/[try]/[if] (not wrapped in [begin]/[end] or - parentheses); such a branch needs a forced break after the comment so that - its body is not indented relative to the comment's end column. *) + if-then-else mode. *) val match_indent : ?default:int -> Conf.t -> parens:bool -> ctx:Ast.t -> int (** [match_indent c ~ctx ~default] returns the indentation used for the diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref index 8de6888f59..1ee520ed62 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref @@ -255,9 +255,9 @@ let _ = if a then b else - (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *)( - match x with - | A -> f) + (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) + (match x with + | A -> f) (* Comment before nested if in then branch - Compact mode oscillation *) let _ = @@ -277,10 +277,10 @@ let _ = if cond then x else - (* a comment *)( - match e with - | A -> a - | B -> b) + (* a comment *) + (match e with + | A -> a + | B -> b) (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref index eab77faebe..2b5f855e4e 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref @@ -265,9 +265,9 @@ let _ = if a then b else - (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *)( - match x with - | A -> f + (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) + (match x with + | A -> f ) (* Comment before nested if in then branch - Compact mode oscillation *) @@ -288,10 +288,10 @@ let _ = if cond then x else - (* a comment *)( - match e with - | A -> a - | B -> b + (* a comment *) + (match e with + | A -> a + | B -> b ) (* A bare [begin match ... end] branch must keep [match ... with] on one line, diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref index 8de6888f59..1ee520ed62 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref @@ -255,9 +255,9 @@ let _ = if a then b else - (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *)( - match x with - | A -> f) + (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) + (match x with + | A -> f) (* Comment before nested if in then branch - Compact mode oscillation *) let _ = @@ -277,10 +277,10 @@ let _ = if cond then x else - (* a comment *)( - match e with - | A -> a - | B -> b) + (* a comment *) + (match e with + | A -> a + | B -> b) (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref index 347d35bb4d..41653cb3f1 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref @@ -271,9 +271,9 @@ let _ = if a then b else - (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *)( - match x with - | A -> f) + (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) + (match x with + | A -> f) ;; (* Comment before nested if in then branch - Compact mode oscillation *) @@ -295,10 +295,10 @@ let _ = if cond then x else - (* a comment *)( - match e with - | A -> a - | B -> b) + (* a comment *) + (match e with + | A -> a + | B -> b) ;; (* A bare [begin match ... end] branch must keep [match ... with] on one line, diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref index 8834bc8e78..4261c925d6 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref @@ -282,9 +282,9 @@ let _ = if a then b else - (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *)( - match x with - | A -> f + (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) + (match x with + | A -> f ) ;; @@ -307,10 +307,10 @@ let _ = if cond then x else - (* a comment *)( - match e with - | A -> a - | B -> b + (* a comment *) + (match e with + | A -> a + | B -> b ) ;; diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref index 347d35bb4d..41653cb3f1 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref @@ -271,9 +271,9 @@ let _ = if a then b else - (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *)( - match x with - | A -> f) + (* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *) + (match x with + | A -> f) ;; (* Comment before nested if in then branch - Compact mode oscillation *) @@ -295,10 +295,10 @@ let _ = if cond then x else - (* a comment *)( - match e with - | A -> a - | B -> b) + (* a comment *) + (match e with + | A -> a + | B -> b) ;; (* A bare [begin match ... end] branch must keep [match ... with] on one line, From d6d89f8e74864529a7446ec13e5c2eaec1bee281 Mon Sep 17 00:00:00 2001 From: Boris Yakobowski Date: Mon, 6 Jul 2026 20:31:27 +0100 Subject: [PATCH 7/7] test: Add regression test for comment before [begin match ... end] Tests the paren-glue behavior: with exp_grouping=parens (janestreet, ahrefs), [begin match ... end] is parsed as a bare match needing parenthesization; a preceding comment must not glue to the opening paren. Without the fix, this renders as: (* a comment *)begin match some_long_scrutinee_expression with | A -> a | B -> b end or (with exp_grouping=parens): (* a comment *) ( match some_long_scrutinee_expression with | A -> a | B -> b) Note: without the preceding fix, janestreet + k-r mode has a pre-existing over-indentation issue for match-in-parens branches (match indented +2 relative to the comment inside the parens). This caused non-convergence with max-iters=3 in the unfixed code; the paren-glue fix resolves the oscillation. Co-Authored-By: Claude Opus 4.6 --- test/passing/refs.ahrefs/ite-compact.ml.ref | 11 +++++++++++ test/passing/refs.ahrefs/ite-compact_closing.ml.ref | 11 +++++++++++ test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref | 12 ++++++++++++ .../refs.ahrefs/ite-fit_or_vertical_closing.ml.ref | 12 ++++++++++++ .../ite-fit_or_vertical_no_indicate.ml.ref | 12 ++++++++++++ test/passing/refs.ahrefs/ite-kr.ml.ref | 12 ++++++++++++ test/passing/refs.ahrefs/ite-kr_closing.ml.ref | 12 ++++++++++++ test/passing/refs.ahrefs/ite-kw_first.ml.ref | 12 ++++++++++++ .../passing/refs.ahrefs/ite-kw_first_closing.ml.ref | 12 ++++++++++++ .../refs.ahrefs/ite-kw_first_no_indicate.ml.ref | 12 ++++++++++++ test/passing/refs.ahrefs/ite-no_indicate.ml.ref | 11 +++++++++++ test/passing/refs.ahrefs/ite-vertical.ml.ref | 12 ++++++++++++ test/passing/refs.ahrefs/ite.ml.ref | 11 +++++++++++ test/passing/refs.default/ite-compact.ml.ref | 9 +++++++++ .../passing/refs.default/ite-compact_closing.ml.ref | 9 +++++++++ .../passing/refs.default/ite-fit_or_vertical.ml.ref | 10 ++++++++++ .../refs.default/ite-fit_or_vertical_closing.ml.ref | 10 ++++++++++ .../ite-fit_or_vertical_no_indicate.ml.ref | 10 ++++++++++ test/passing/refs.default/ite-kr.ml.ref | 10 ++++++++++ test/passing/refs.default/ite-kr_closing.ml.ref | 10 ++++++++++ test/passing/refs.default/ite-kw_first.ml.ref | 10 ++++++++++ .../refs.default/ite-kw_first_closing.ml.ref | 10 ++++++++++ .../refs.default/ite-kw_first_no_indicate.ml.ref | 10 ++++++++++ test/passing/refs.default/ite-no_indicate.ml.ref | 9 +++++++++ test/passing/refs.default/ite-vertical.ml.ref | 10 ++++++++++ test/passing/refs.default/ite.ml.ref | 9 +++++++++ test/passing/refs.janestreet/ite-compact.ml.ref | 11 +++++++++++ .../refs.janestreet/ite-compact_closing.ml.ref | 12 ++++++++++++ .../refs.janestreet/ite-fit_or_vertical.ml.ref | 12 ++++++++++++ .../ite-fit_or_vertical_closing.ml.ref | 13 +++++++++++++ .../ite-fit_or_vertical_no_indicate.ml.ref | 12 ++++++++++++ test/passing/refs.janestreet/ite-kr.ml.ref | 13 +++++++++++++ test/passing/refs.janestreet/ite-kr_closing.ml.ref | 13 +++++++++++++ test/passing/refs.janestreet/ite-kw_first.ml.ref | 12 ++++++++++++ .../refs.janestreet/ite-kw_first_closing.ml.ref | 13 +++++++++++++ .../refs.janestreet/ite-kw_first_no_indicate.ml.ref | 12 ++++++++++++ test/passing/refs.janestreet/ite-no_indicate.ml.ref | 11 +++++++++++ test/passing/refs.janestreet/ite-vertical.ml.ref | 12 ++++++++++++ test/passing/refs.janestreet/ite.ml.ref | 11 +++++++++++ test/passing/refs.ocamlformat/ite-compact.ml.ref | 9 +++++++++ .../refs.ocamlformat/ite-compact_closing.ml.ref | 9 +++++++++ .../refs.ocamlformat/ite-fit_or_vertical.ml.ref | 10 ++++++++++ .../ite-fit_or_vertical_closing.ml.ref | 10 ++++++++++ .../ite-fit_or_vertical_no_indicate.ml.ref | 10 ++++++++++ test/passing/refs.ocamlformat/ite-kr.ml.ref | 10 ++++++++++ test/passing/refs.ocamlformat/ite-kr_closing.ml.ref | 10 ++++++++++ test/passing/refs.ocamlformat/ite-kw_first.ml.ref | 10 ++++++++++ .../refs.ocamlformat/ite-kw_first_closing.ml.ref | 10 ++++++++++ .../ite-kw_first_no_indicate.ml.ref | 10 ++++++++++ .../passing/refs.ocamlformat/ite-no_indicate.ml.ref | 9 +++++++++ test/passing/refs.ocamlformat/ite-vertical.ml.ref | 10 ++++++++++ test/passing/refs.ocamlformat/ite.ml.ref | 9 +++++++++ test/passing/tests/ite.ml | 11 +++++++++++ 53 files changed, 572 insertions(+) diff --git a/test/passing/refs.ahrefs/ite-compact.ml.ref b/test/passing/refs.ahrefs/ite-compact.ml.ref index f44cf85017..e649fbc206 100644 --- a/test/passing/refs.ahrefs/ite-compact.ml.ref +++ b/test/passing/refs.ahrefs/ite-compact.ml.ref @@ -241,6 +241,17 @@ let _ = | A -> a | B -> b) +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ahrefs/ite-compact_closing.ml.ref b/test/passing/refs.ahrefs/ite-compact_closing.ml.ref index 4a0d1b6905..ece1f0c637 100644 --- a/test/passing/refs.ahrefs/ite-compact_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-compact_closing.ml.ref @@ -262,6 +262,17 @@ let _ = | B -> b ) +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref index 1ee520ed62..86f381d59c 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical.ml.ref @@ -282,6 +282,18 @@ let _ = | A -> a | B -> b) +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref index 2b5f855e4e..3f8bdccfd1 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_closing.ml.ref @@ -294,6 +294,18 @@ let _ = | B -> b ) +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref index 1ee520ed62..86f381d59c 100644 --- a/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-fit_or_vertical_no_indicate.ml.ref @@ -282,6 +282,18 @@ let _ = | A -> a | B -> b) +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ahrefs/ite-kr.ml.ref b/test/passing/refs.ahrefs/ite-kr.ml.ref index ee12580364..a86d5a549d 100644 --- a/test/passing/refs.ahrefs/ite-kr.ml.ref +++ b/test/passing/refs.ahrefs/ite-kr.ml.ref @@ -323,6 +323,18 @@ let _ = | B -> b ) +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ahrefs/ite-kr_closing.ml.ref b/test/passing/refs.ahrefs/ite-kr_closing.ml.ref index dc29beba54..540f41e3ad 100644 --- a/test/passing/refs.ahrefs/ite-kr_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-kr_closing.ml.ref @@ -330,6 +330,18 @@ let _ = | B -> b ) +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ahrefs/ite-kw_first.ml.ref b/test/passing/refs.ahrefs/ite-kw_first.ml.ref index dd70adb89b..09b9ae024f 100644 --- a/test/passing/refs.ahrefs/ite-kw_first.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first.ml.ref @@ -277,6 +277,18 @@ let _ = | A -> a | B -> b) +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref b/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref index 1b5d18b7a2..157cadaacc 100644 --- a/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first_closing.ml.ref @@ -298,6 +298,18 @@ let _ = | B -> b ) +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref index dd70adb89b..09b9ae024f 100644 --- a/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-kw_first_no_indicate.ml.ref @@ -277,6 +277,18 @@ let _ = | A -> a | B -> b) +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ahrefs/ite-no_indicate.ml.ref b/test/passing/refs.ahrefs/ite-no_indicate.ml.ref index f44cf85017..e649fbc206 100644 --- a/test/passing/refs.ahrefs/ite-no_indicate.ml.ref +++ b/test/passing/refs.ahrefs/ite-no_indicate.ml.ref @@ -241,6 +241,17 @@ let _ = | A -> a | B -> b) +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ahrefs/ite-vertical.ml.ref b/test/passing/refs.ahrefs/ite-vertical.ml.ref index 0d1facddd2..476de3cbaa 100644 --- a/test/passing/refs.ahrefs/ite-vertical.ml.ref +++ b/test/passing/refs.ahrefs/ite-vertical.ml.ref @@ -320,6 +320,18 @@ let _ = | A -> a | B -> b) +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ahrefs/ite.ml.ref b/test/passing/refs.ahrefs/ite.ml.ref index f44cf85017..e649fbc206 100644 --- a/test/passing/refs.ahrefs/ite.ml.ref +++ b/test/passing/refs.ahrefs/ite.ml.ref @@ -241,6 +241,17 @@ let _ = | A -> a | B -> b) +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.default/ite-compact.ml.ref b/test/passing/refs.default/ite-compact.ml.ref index df0da3bd91..ec66086711 100644 --- a/test/passing/refs.default/ite-compact.ml.ref +++ b/test/passing/refs.default/ite-compact.ml.ref @@ -232,6 +232,15 @@ let _ = (* a comment *) match e with A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.default/ite-compact_closing.ml.ref b/test/passing/refs.default/ite-compact_closing.ml.ref index 95d3fc81d2..09e4a41458 100644 --- a/test/passing/refs.default/ite-compact_closing.ml.ref +++ b/test/passing/refs.default/ite-compact_closing.ml.ref @@ -247,6 +247,15 @@ let _ = (* a comment *) match e with A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.default/ite-fit_or_vertical.ml.ref b/test/passing/refs.default/ite-fit_or_vertical.ml.ref index a53c85526a..59312b943e 100644 --- a/test/passing/refs.default/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical.ml.ref @@ -282,6 +282,16 @@ let _ = | A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref index fadf4b0dac..5da15c44f3 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical_closing.ml.ref @@ -291,6 +291,16 @@ let _ = | A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref index a53c85526a..59312b943e 100644 --- a/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.default/ite-fit_or_vertical_no_indicate.ml.ref @@ -282,6 +282,16 @@ let _ = | A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.default/ite-kr.ml.ref b/test/passing/refs.default/ite-kr.ml.ref index c8a446a7c5..2b0434dfc3 100644 --- a/test/passing/refs.default/ite-kr.ml.ref +++ b/test/passing/refs.default/ite-kr.ml.ref @@ -315,6 +315,16 @@ let _ = else (* a comment *) match e with A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.default/ite-kr_closing.ml.ref b/test/passing/refs.default/ite-kr_closing.ml.ref index 040f27eb2d..e952383e8d 100644 --- a/test/passing/refs.default/ite-kr_closing.ml.ref +++ b/test/passing/refs.default/ite-kr_closing.ml.ref @@ -322,6 +322,16 @@ let _ = else (* a comment *) match e with A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.default/ite-kw_first.ml.ref b/test/passing/refs.default/ite-kw_first.ml.ref index d4c9595975..bedcc2f63e 100644 --- a/test/passing/refs.default/ite-kw_first.ml.ref +++ b/test/passing/refs.default/ite-kw_first.ml.ref @@ -271,6 +271,16 @@ let _ = | A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.default/ite-kw_first_closing.ml.ref b/test/passing/refs.default/ite-kw_first_closing.ml.ref index 76186d0795..9a061ca15d 100644 --- a/test/passing/refs.default/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.default/ite-kw_first_closing.ml.ref @@ -286,6 +286,16 @@ let _ = | A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref index d4c9595975..bedcc2f63e 100644 --- a/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.default/ite-kw_first_no_indicate.ml.ref @@ -271,6 +271,16 @@ let _ = | A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.default/ite-no_indicate.ml.ref b/test/passing/refs.default/ite-no_indicate.ml.ref index df0da3bd91..ec66086711 100644 --- a/test/passing/refs.default/ite-no_indicate.ml.ref +++ b/test/passing/refs.default/ite-no_indicate.ml.ref @@ -232,6 +232,15 @@ let _ = (* a comment *) match e with A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.default/ite-vertical.ml.ref b/test/passing/refs.default/ite-vertical.ml.ref index 299720fb0c..e667a06c8b 100644 --- a/test/passing/refs.default/ite-vertical.ml.ref +++ b/test/passing/refs.default/ite-vertical.ml.ref @@ -322,6 +322,16 @@ let _ = | A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.default/ite.ml.ref b/test/passing/refs.default/ite.ml.ref index df0da3bd91..ec66086711 100644 --- a/test/passing/refs.default/ite.ml.ref +++ b/test/passing/refs.default/ite.ml.ref @@ -232,6 +232,15 @@ let _ = (* a comment *) match e with A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.janestreet/ite-compact.ml.ref b/test/passing/refs.janestreet/ite-compact.ml.ref index a9bb04fced..4648348f9f 100644 --- a/test/passing/refs.janestreet/ite-compact.ml.ref +++ b/test/passing/refs.janestreet/ite-compact.ml.ref @@ -247,6 +247,17 @@ let _ = | B -> b) ;; +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b) +;; + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.janestreet/ite-compact_closing.ml.ref b/test/passing/refs.janestreet/ite-compact_closing.ml.ref index 4c438df481..b5c5cd3afc 100644 --- a/test/passing/refs.janestreet/ite-compact_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-compact_closing.ml.ref @@ -263,6 +263,18 @@ let _ = ) ;; +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b + ) +;; + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref index 41653cb3f1..908b7c640f 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical.ml.ref @@ -301,6 +301,18 @@ let _ = | B -> b) ;; +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + (match some_long_scrutinee_expression with + | A -> a + | B -> b) +;; + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref index 4261c925d6..22664483fc 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical_closing.ml.ref @@ -314,6 +314,19 @@ let _ = ) ;; +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + (match some_long_scrutinee_expression with + | A -> a + | B -> b + ) +;; + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref index 41653cb3f1..908b7c640f 100644 --- a/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-fit_or_vertical_no_indicate.ml.ref @@ -301,6 +301,18 @@ let _ = | B -> b) ;; +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + (match some_long_scrutinee_expression with + | A -> a + | B -> b) +;; + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.janestreet/ite-kr.ml.ref b/test/passing/refs.janestreet/ite-kr.ml.ref index 8914e9364b..2870979727 100644 --- a/test/passing/refs.janestreet/ite-kr.ml.ref +++ b/test/passing/refs.janestreet/ite-kr.ml.ref @@ -350,6 +350,19 @@ let _ = ) ;; +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b + ) +;; + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.janestreet/ite-kr_closing.ml.ref b/test/passing/refs.janestreet/ite-kr_closing.ml.ref index 62a53ce1fa..bfe303577a 100644 --- a/test/passing/refs.janestreet/ite-kr_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-kr_closing.ml.ref @@ -357,6 +357,19 @@ let _ = ) ;; +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b + ) +;; + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.janestreet/ite-kw_first.ml.ref b/test/passing/refs.janestreet/ite-kw_first.ml.ref index 676e727232..e9b034405b 100644 --- a/test/passing/refs.janestreet/ite-kw_first.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first.ml.ref @@ -282,6 +282,18 @@ let _ = | B -> b) ;; +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b) +;; + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref b/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref index 42bb8cbc7b..e203a272fe 100644 --- a/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first_closing.ml.ref @@ -298,6 +298,19 @@ let _ = ) ;; +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b + ) +;; + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref index 676e727232..e9b034405b 100644 --- a/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first_no_indicate.ml.ref @@ -282,6 +282,18 @@ let _ = | B -> b) ;; +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b) +;; + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.janestreet/ite-no_indicate.ml.ref b/test/passing/refs.janestreet/ite-no_indicate.ml.ref index a9bb04fced..4648348f9f 100644 --- a/test/passing/refs.janestreet/ite-no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-no_indicate.ml.ref @@ -247,6 +247,17 @@ let _ = | B -> b) ;; +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b) +;; + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.janestreet/ite-vertical.ml.ref b/test/passing/refs.janestreet/ite-vertical.ml.ref index ed633fe784..74865e32b4 100644 --- a/test/passing/refs.janestreet/ite-vertical.ml.ref +++ b/test/passing/refs.janestreet/ite-vertical.ml.ref @@ -346,6 +346,18 @@ let _ = | B -> b) ;; +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b) +;; + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.janestreet/ite.ml.ref b/test/passing/refs.janestreet/ite.ml.ref index a9bb04fced..4648348f9f 100644 --- a/test/passing/refs.janestreet/ite.ml.ref +++ b/test/passing/refs.janestreet/ite.ml.ref @@ -247,6 +247,17 @@ let _ = | B -> b) ;; +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else ( + (* a comment *) + match some_long_scrutinee_expression with + | A -> a + | B -> b) +;; + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ocamlformat/ite-compact.ml.ref b/test/passing/refs.ocamlformat/ite-compact.ml.ref index 5c1d33eaca..0138bd452d 100644 --- a/test/passing/refs.ocamlformat/ite-compact.ml.ref +++ b/test/passing/refs.ocamlformat/ite-compact.ml.ref @@ -231,6 +231,15 @@ let _ = (* a comment *) match e with A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref b/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref index 9226ebbccb..8b3bfca819 100644 --- a/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-compact_closing.ml.ref @@ -241,6 +241,15 @@ let _ = (* a comment *) match e with A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref index c7bb0c0543..465a451644 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical.ml.ref @@ -288,6 +288,16 @@ let _ = | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref index 19b6ca204a..b964a93091 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_closing.ml.ref @@ -293,6 +293,16 @@ let _ = | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref index 3535e98ef6..41fa87983f 100644 --- a/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-fit_or_vertical_no_indicate.ml.ref @@ -285,6 +285,16 @@ let _ = | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ocamlformat/ite-kr.ml.ref b/test/passing/refs.ocamlformat/ite-kr.ml.ref index 06edf9e8d6..3922823762 100644 --- a/test/passing/refs.ocamlformat/ite-kr.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kr.ml.ref @@ -317,6 +317,16 @@ let _ = else (* a comment *) match e with A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref b/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref index 0c652349bd..afbfcc262a 100644 --- a/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kr_closing.ml.ref @@ -321,6 +321,16 @@ let _ = else (* a comment *) match e with A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ocamlformat/ite-kw_first.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first.ml.ref index a528e27e79..d375c12b31 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first.ml.ref @@ -272,6 +272,16 @@ let _ = | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref index 57e731abbf..fbfca33277 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first_closing.ml.ref @@ -282,6 +282,16 @@ let _ = | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref index 5ae17c4ef6..e9eae18493 100644 --- a/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-kw_first_no_indicate.ml.ref @@ -269,6 +269,16 @@ let _ = | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond + then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref b/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref index 23c01681ba..5512f98336 100644 --- a/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref +++ b/test/passing/refs.ocamlformat/ite-no_indicate.ml.ref @@ -228,6 +228,15 @@ let _ = (* a comment *) match e with A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ocamlformat/ite-vertical.ml.ref b/test/passing/refs.ocamlformat/ite-vertical.ml.ref index 9d4e4ff10f..6bf6ca9f85 100644 --- a/test/passing/refs.ocamlformat/ite-vertical.ml.ref +++ b/test/passing/refs.ocamlformat/ite-vertical.ml.ref @@ -330,6 +330,16 @@ let _ = | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then + x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/refs.ocamlformat/ite.ml.ref b/test/passing/refs.ocamlformat/ite.ml.ref index 5c1d33eaca..0138bd452d 100644 --- a/test/passing/refs.ocamlformat/ite.ml.ref +++ b/test/passing/refs.ocamlformat/ite.ml.ref @@ -231,6 +231,15 @@ let _ = (* a comment *) match e with A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with A -> a | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *) diff --git a/test/passing/tests/ite.ml b/test/passing/tests/ite.ml index 71796f892e..d324aa074d 100644 --- a/test/passing/tests/ite.ml +++ b/test/passing/tests/ite.ml @@ -238,6 +238,17 @@ let _ = | A -> a | B -> b +(* Comment before [begin match ... end]: comment must not glue to [begin] + (regression test for paren-glue in profiles with exp_grouping=parens) *) +let _ = + if cond then x + else + (* a comment *) + begin match some_long_scrutinee_expression with + | A -> a + | B -> b + end + (* A bare [begin match ... end] branch must keep [match ... with] on one line, not split it as [begin match] / scrutinee / [with], and must align [end] with [begin] (regression test) *)