diff --git a/CHANGES.md b/CHANGES.md index 67dcb7faac..30269a36cd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,18 @@ 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. + (#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..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 @@ -2593,7 +2594,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 = @@ -3034,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 155f82c562..2d69f28b5a 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 = @@ -858,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= [] @@ -878,6 +898,19 @@ 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 let infix_ext_attrs_beginend = @@ -929,31 +962,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 ~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 ~bare_branch 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: @@ -973,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 @@ -982,24 +1024,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 +1031,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: @@ -1016,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 @@ -1040,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 776ba51399..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 @@ -242,10 +243,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..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) *) @@ -230,3 +230,24 @@ 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) + +(* 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 5325ce7382..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) *) @@ -250,3 +250,25 @@ 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 + ) + +(* 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 f6dbbe1bc9..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 @@ -273,3 +270,26 @@ 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) + +(* 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 568bde8b61..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 @@ -284,3 +281,27 @@ 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 + ) + +(* 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 f6dbbe1bc9..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 @@ -273,3 +270,26 @@ 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) + +(* 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 40be4b4384..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 @@ -310,3 +310,27 @@ 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 + ) + +(* 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 fdf791c892..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 @@ -317,3 +317,27 @@ 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 + ) + +(* 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 0dd5acf1bc..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) *) @@ -265,3 +265,26 @@ 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) + +(* 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 e0b9284f1d..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) *) @@ -285,3 +285,27 @@ 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 + ) + +(* 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 0dd5acf1bc..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) *) @@ -265,3 +265,26 @@ 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) + +(* 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 62816583fb..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) *) @@ -230,3 +230,24 @@ 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) + +(* 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 6d41adb8e8..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) *) @@ -310,3 +308,26 @@ 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) + +(* 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 62816583fb..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) *) @@ -230,3 +230,24 @@ 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) + +(* 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 3672c44671..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) *) @@ -223,3 +223,22 @@ 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 + +(* 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 8fc1245502..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) *) @@ -238,3 +238,22 @@ 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 + +(* 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 4214040eeb..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 @@ -259,8 +256,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 +270,26 @@ 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 + +(* 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 64810afbfe..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 @@ -268,8 +265,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 +279,26 @@ 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 + +(* 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 4214040eeb..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 @@ -259,8 +256,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 +270,26 @@ 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 + +(* 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 0773c03e16..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 @@ -306,3 +306,23 @@ 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 + +(* 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 d16ca01a77..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 @@ -313,3 +313,23 @@ 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 + +(* 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 a0941721b7..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) *) @@ -259,3 +259,26 @@ 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 + +(* 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 546b602f91..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) *) @@ -274,3 +274,26 @@ 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 + +(* 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 a0941721b7..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) *) @@ -259,3 +259,26 @@ 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 + +(* 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 3672c44671..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) *) @@ -223,3 +223,22 @@ 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 + +(* 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 04eb6fbb61..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) *) @@ -312,3 +310,26 @@ 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 + +(* 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 3672c44671..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) *) @@ -223,3 +223,22 @@ 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 + +(* 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 02d22ac756..a9bb04fced 100644 --- a/test/passing/refs.janestreet/ite-compact.ml.ref +++ b/test/passing/refs.janestreet/ite-compact.ml.ref @@ -235,3 +235,25 @@ 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) +;; + +(* 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 e98406e08f..4c438df481 100644 --- a/test/passing/refs.janestreet/ite-compact_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-compact_closing.ml.ref @@ -250,3 +250,27 @@ 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 + ) +;; + +(* 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 35c0fdedf6..347d35bb4d 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,27 @@ 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) +;; + +(* 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 97b3d2aca5..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 @@ -300,3 +300,29 @@ 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 + ) +;; + +(* 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 35c0fdedf6..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 @@ -288,3 +288,27 @@ 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) +;; + +(* 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 20a2ed5f27..8914e9364b 100644 --- a/test/passing/refs.janestreet/ite-kr.ml.ref +++ b/test/passing/refs.janestreet/ite-kr.ml.ref @@ -336,3 +336,29 @@ 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 + ) +;; + +(* 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 0bcf83e649..62a53ce1fa 100644 --- a/test/passing/refs.janestreet/ite-kr_closing.ml.ref +++ b/test/passing/refs.janestreet/ite-kr_closing.ml.ref @@ -343,3 +343,29 @@ 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 + ) +;; + +(* 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 2b16944d25..676e727232 100644 --- a/test/passing/refs.janestreet/ite-kw_first.ml.ref +++ b/test/passing/refs.janestreet/ite-kw_first.ml.ref @@ -269,3 +269,27 @@ 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) +;; + +(* 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 3111239793..42bb8cbc7b 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,29 @@ 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 + ) +;; + +(* 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 2b16944d25..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 @@ -269,3 +269,27 @@ 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) +;; + +(* 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 02d22ac756..a9bb04fced 100644 --- a/test/passing/refs.janestreet/ite-no_indicate.ml.ref +++ b/test/passing/refs.janestreet/ite-no_indicate.ml.ref @@ -235,3 +235,25 @@ 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) +;; + +(* 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 d99e8aad56..ed633fe784 100644 --- a/test/passing/refs.janestreet/ite-vertical.ml.ref +++ b/test/passing/refs.janestreet/ite-vertical.ml.ref @@ -333,3 +333,27 @@ 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) +;; + +(* 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 02d22ac756..a9bb04fced 100644 --- a/test/passing/refs.janestreet/ite.ml.ref +++ b/test/passing/refs.janestreet/ite.ml.ref @@ -235,3 +235,25 @@ 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) +;; + +(* 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 4860d9f001..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) *) @@ -222,3 +222,24 @@ 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 + +(* 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 d7fb7bea79..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) *) @@ -232,3 +232,24 @@ 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 + +(* 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 dba064e102..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 @@ -262,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 _ = @@ -277,3 +274,30 @@ 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 + +(* 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 fda9f31bfd..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 @@ -267,9 +264,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 +279,30 @@ 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 + +(* 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 5faeb08f42..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 @@ -259,9 +256,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 +271,30 @@ 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 + +(* 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 7a8ac0e004..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 @@ -308,3 +308,25 @@ 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 + +(* 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 ca04feee60..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 @@ -312,3 +312,25 @@ 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 + +(* 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 df8130036d..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) *) @@ -258,3 +258,30 @@ 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 + +(* 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 b10567c2e3..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) *) @@ -268,3 +268,30 @@ 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 + +(* 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 1644f1dd7d..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) *) @@ -255,3 +255,30 @@ 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 + +(* 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 8665872059..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) *) @@ -219,3 +219,24 @@ 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 + +(* 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 8108fa2e00..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) *) @@ -318,3 +316,30 @@ 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 + +(* 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 4860d9f001..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) *) @@ -222,3 +222,24 @@ 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 + +(* 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 0bdab6413b..71796f892e 100644 --- a/test/passing/tests/ite.ml +++ b/test/passing/tests/ite.ml @@ -227,3 +227,24 @@ 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 + +(* 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