From 20be4875322c0737f93b7bb929552a168e3a9d6c Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Wed, 10 Jan 2024 11:35:57 +0100 Subject: [PATCH 01/10] Add failing test --- test/passing/tests/ite-compact.ml.ref | 4 ++++ test/passing/tests/ite-compact_closing.ml.ref | 4 ++++ test/passing/tests/ite-fit_or_vertical.ml.ref | 10 ++++++++++ test/passing/tests/ite-fit_or_vertical_closing.ml.ref | 10 ++++++++++ .../tests/ite-fit_or_vertical_no_indicate.ml.ref | 10 ++++++++++ test/passing/tests/ite-kr.ml.ref | 10 ++++++++++ test/passing/tests/ite-kr_closing.ml.ref | 10 ++++++++++ test/passing/tests/ite-kw_first.ml.ref | 4 ++++ test/passing/tests/ite-kw_first_closing.ml.ref | 4 ++++ test/passing/tests/ite-kw_first_no_indicate.ml.ref | 4 ++++ test/passing/tests/ite-no_indicate.ml.ref | 4 ++++ test/passing/tests/ite-vertical.ml.ref | 10 ++++++++++ test/passing/tests/ite.ml | 7 +++++++ test/passing/tests/ite.ml.ref | 4 ++++ 14 files changed, 95 insertions(+) diff --git a/test/passing/tests/ite-compact.ml.ref b/test/passing/tests/ite-compact.ml.ref index 47fb9ae628..2f87f95266 100644 --- a/test/passing/tests/ite-compact.ml.ref +++ b/test/passing/tests/ite-compact.ml.ref @@ -137,3 +137,7 @@ let _ = xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + +let _ = if (* foo *) + foo then 0 else if (* bar *) + bar then 1 else 2 diff --git a/test/passing/tests/ite-compact_closing.ml.ref b/test/passing/tests/ite-compact_closing.ml.ref index 7a7e5e1008..eb3741166d 100644 --- a/test/passing/tests/ite-compact_closing.ml.ref +++ b/test/passing/tests/ite-compact_closing.ml.ref @@ -152,3 +152,7 @@ let _ = xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + +let _ = if (* foo *) + foo then 0 else if (* bar *) + bar then 1 else 2 diff --git a/test/passing/tests/ite-fit_or_vertical.ml.ref b/test/passing/tests/ite-fit_or_vertical.ml.ref index 788fcace37..b4053d7e8e 100644 --- a/test/passing/tests/ite-fit_or_vertical.ml.ref +++ b/test/passing/tests/ite-fit_or_vertical.ml.ref @@ -168,3 +168,13 @@ let _ = else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + +let _ = + if (* foo *) + foo then + 0 + else if (* bar *) + bar then + 1 + else + 2 diff --git a/test/passing/tests/ite-fit_or_vertical_closing.ml.ref b/test/passing/tests/ite-fit_or_vertical_closing.ml.ref index 812812584e..55cfb2e4bc 100644 --- a/test/passing/tests/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/tests/ite-fit_or_vertical_closing.ml.ref @@ -180,3 +180,13 @@ let _ = else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + +let _ = + if (* foo *) + foo then + 0 + else if (* bar *) + bar then + 1 + else + 2 diff --git a/test/passing/tests/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/tests/ite-fit_or_vertical_no_indicate.ml.ref index 8b92178848..9ec03f6d2c 100644 --- a/test/passing/tests/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/tests/ite-fit_or_vertical_no_indicate.ml.ref @@ -168,3 +168,13 @@ let _ = else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + +let _ = + if (* foo *) + foo then + 0 + else if (* bar *) + bar then + 1 + else + 2 diff --git a/test/passing/tests/ite-kr.ml.ref b/test/passing/tests/ite-kr.ml.ref index 631b238ebf..20f7008a91 100644 --- a/test/passing/tests/ite-kr.ml.ref +++ b/test/passing/tests/ite-kr.ml.ref @@ -203,3 +203,13 @@ let _ = else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + +let _ = + if (* foo *) + foo then + 0 + else if (* bar *) + bar then + 1 + else + 2 diff --git a/test/passing/tests/ite-kr_closing.ml.ref b/test/passing/tests/ite-kr_closing.ml.ref index 3f70b3b86f..6289345dfd 100644 --- a/test/passing/tests/ite-kr_closing.ml.ref +++ b/test/passing/tests/ite-kr_closing.ml.ref @@ -213,3 +213,13 @@ let _ = else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + +let _ = + if (* foo *) + foo then + 0 + else if (* bar *) + bar then + 1 + else + 2 diff --git a/test/passing/tests/ite-kw_first.ml.ref b/test/passing/tests/ite-kw_first.ml.ref index 09d8646acc..20cdd01137 100644 --- a/test/passing/tests/ite-kw_first.ml.ref +++ b/test/passing/tests/ite-kw_first.ml.ref @@ -160,3 +160,7 @@ let _ = else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + +let _ = if (* foo *) + foo then 0 else if (* bar *) + bar then 1 else 2 diff --git a/test/passing/tests/ite-kw_first_closing.ml.ref b/test/passing/tests/ite-kw_first_closing.ml.ref index 77a21cb637..890d3d087e 100644 --- a/test/passing/tests/ite-kw_first_closing.ml.ref +++ b/test/passing/tests/ite-kw_first_closing.ml.ref @@ -175,3 +175,7 @@ let _ = else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + +let _ = if (* foo *) + foo then 0 else if (* bar *) + bar then 1 else 2 diff --git a/test/passing/tests/ite-kw_first_no_indicate.ml.ref b/test/passing/tests/ite-kw_first_no_indicate.ml.ref index 7915d7551b..e1cafcd1bc 100644 --- a/test/passing/tests/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/tests/ite-kw_first_no_indicate.ml.ref @@ -159,3 +159,7 @@ let _ = else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + +let _ = if (* foo *) + foo then 0 else if (* bar *) + bar then 1 else 2 diff --git a/test/passing/tests/ite-no_indicate.ml.ref b/test/passing/tests/ite-no_indicate.ml.ref index c7f2d87ae8..df7bc50960 100644 --- a/test/passing/tests/ite-no_indicate.ml.ref +++ b/test/passing/tests/ite-no_indicate.ml.ref @@ -136,3 +136,7 @@ let _ = xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + +let _ = if (* foo *) + foo then 0 else if (* bar *) + bar then 1 else 2 diff --git a/test/passing/tests/ite-vertical.ml.ref b/test/passing/tests/ite-vertical.ml.ref index 7624be7f37..aa6d5c8c57 100644 --- a/test/passing/tests/ite-vertical.ml.ref +++ b/test/passing/tests/ite-vertical.ml.ref @@ -199,3 +199,13 @@ let _ = else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + +let _ = + if (* foo *) + foo then + 0 + else if (* bar *) + bar then + 1 + else + 2 diff --git a/test/passing/tests/ite.ml b/test/passing/tests/ite.ml index 910d40a169..6f4c3aa98f 100644 --- a/test/passing/tests/ite.ml +++ b/test/passing/tests/ite.ml @@ -139,3 +139,10 @@ let _ = else (fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz) + +let _ = + if (* foo *) + foo then 0 + else if (* bar *) + bar then 1 + else 2 diff --git a/test/passing/tests/ite.ml.ref b/test/passing/tests/ite.ml.ref index 47fb9ae628..2f87f95266 100644 --- a/test/passing/tests/ite.ml.ref +++ b/test/passing/tests/ite.ml.ref @@ -137,3 +137,7 @@ let _ = xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + +let _ = if (* foo *) + foo then 0 else if (* bar *) + bar then 1 else 2 From 5ba5f6b949be8b53b4b5a2641680a0ad1088fee5 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 11 Jan 2024 16:16:09 +0100 Subject: [PATCH 02/10] Fix unwanted alignment after comment This removes the alignment in expressions like: let _ = try_with (fun () -> (* comment before *) a ; b (* after b *) ) --- lib/Cmts.ml | 4 ++-- test/passing/tests/comments-no-wrap.ml.err | 2 +- test/passing/tests/comments-no-wrap.ml.ref | 16 ++++++++++------ test/passing/tests/comments.ml.ref | 16 ++++++++++------ test/passing/tests/comments_args.ml.ref | 3 ++- test/passing/tests/extensions-indent.ml.ref | 5 ++++- test/passing/tests/extensions.ml.ref | 5 ++++- .../tests/extensions_exp_grouping.ml.ref | 7 +++++-- test/passing/tests/ite-compact.ml.ref | 19 ++++++++++++++----- test/passing/tests/ite-compact_closing.ml.ref | 19 ++++++++++++++----- test/passing/tests/ite-fit_or_vertical.ml.ref | 12 ++++++++---- .../tests/ite-fit_or_vertical_closing.ml.ref | 12 ++++++++---- .../ite-fit_or_vertical_no_indicate.ml.ref | 12 ++++++++---- test/passing/tests/ite-kr.ml.ref | 12 ++++++++---- test/passing/tests/ite-kr_closing.ml.ref | 12 ++++++++---- test/passing/tests/ite-kw_first.ml.ref | 17 ++++++++++++----- .../passing/tests/ite-kw_first_closing.ml.ref | 17 ++++++++++++----- .../tests/ite-kw_first_no_indicate.ml.ref | 17 ++++++++++++----- test/passing/tests/ite-no_indicate.ml.ref | 19 ++++++++++++++----- test/passing/tests/ite-vertical.ml.ref | 12 ++++++++---- test/passing/tests/ite.ml.ref | 19 ++++++++++++++----- test/passing/tests/js_args.ml.ref | 16 ++++++++++++---- test/passing/tests/js_record.ml.ref | 12 ++++++++---- test/passing/tests/js_source.ml.err | 12 ++++++------ test/passing/tests/js_source.ml.ocp | 9 ++++++--- test/passing/tests/js_source.ml.ref | 9 ++++++--- test/passing/tests/let_module-sparse.ml.ref | 3 ++- test/passing/tests/let_module.ml.ref | 3 ++- test/passing/tests/module.ml | 6 ++++-- test/passing/tests/revapply_ext.ml | 9 +++++---- test/passing/tests/shortcut_ext_attr.ml | 7 +++++-- test/passing/tests/source.ml.err | 4 ++-- test/passing/tests/source.ml.ref | 10 +++++++--- 33 files changed, 243 insertions(+), 114 deletions(-) diff --git a/lib/Cmts.ml b/lib/Cmts.ml index 72bbca00a8..e39a1e57e7 100644 --- a/lib/Cmts.ml +++ b/lib/Cmts.ml @@ -615,8 +615,8 @@ let fmt_cmts_aux t (conf : Conf.t) cmts ~fmt_code pos = | _ -> noop ) ) (** Format comments for loc. *) -let fmt_cmts t conf ~fmt_code ?pro ?epi ?(eol = Fmt.fmt "@\n") ?(adj = eol) - found loc pos = +let fmt_cmts t conf ~fmt_code ?pro ?epi ?(eol = Fmt.fmt "@;<1000 0>") + ?(adj = eol) found loc pos = let open Fmt in match found with | None | Some [] -> noop diff --git a/test/passing/tests/comments-no-wrap.ml.err b/test/passing/tests/comments-no-wrap.ml.err index 5c4f0cb901..82121cfa75 100644 --- a/test/passing/tests/comments-no-wrap.ml.err +++ b/test/passing/tests/comments-no-wrap.ml.err @@ -1,4 +1,4 @@ Warning: tests/comments.ml:186 exceeds the margin Warning: tests/comments.ml:190 exceeds the margin Warning: tests/comments.ml:250 exceeds the margin -Warning: tests/comments.ml:430 exceeds the margin +Warning: tests/comments.ml:434 exceeds the margin diff --git a/test/passing/tests/comments-no-wrap.ml.ref b/test/passing/tests/comments-no-wrap.ml.ref index 83d39cc4b1..0d015cf693 100644 --- a/test/passing/tests/comments-no-wrap.ml.ref +++ b/test/passing/tests/comments-no-wrap.ml.ref @@ -252,8 +252,11 @@ let%map _ = () -type t = < (* a *) - a: int [@atr] (* b *) ; b: int (* c *) > +type t = + < (* a *) + a: int [@atr] (* b *) + ; b: int + (* c *) > type t = < a: int (* a *) ; (* b *) .. (* c *) > @@ -277,8 +280,10 @@ let _ = | None -> do_something () | Some _ -> () (* do nothing *) ) -let _ = try_with (fun () -> (* comment before *) - a ; b (* after b *) ) +let _ = + try_with (fun () -> + (* comment before *) + a ; b (* after b *) ) let _ = match x with @@ -296,8 +301,7 @@ type t = type t = (* | B *) - | A - (* A *) + | A (* A *) | C type t = diff --git a/test/passing/tests/comments.ml.ref b/test/passing/tests/comments.ml.ref index caef01c065..e7c66948bf 100644 --- a/test/passing/tests/comments.ml.ref +++ b/test/passing/tests/comments.ml.ref @@ -254,8 +254,11 @@ let%map _ = () -type t = < (* a *) - a: int [@atr] (* b *) ; b: int (* c *) > +type t = + < (* a *) + a: int [@atr] (* b *) + ; b: int + (* c *) > type t = < a: int (* a *) ; (* b *) .. (* c *) > @@ -279,8 +282,10 @@ let _ = | None -> do_something () | Some _ -> () (* do nothing *) ) -let _ = try_with (fun () -> (* comment before *) - a ; b (* after b *) ) +let _ = + try_with (fun () -> + (* comment before *) + a ; b (* after b *) ) let _ = match x with @@ -298,8 +303,7 @@ type t = type t = (* | B *) - | A - (* A *) + | A (* A *) | C type t = diff --git a/test/passing/tests/comments_args.ml.ref b/test/passing/tests/comments_args.ml.ref index 4ddb86c21f..4825fb9904 100644 --- a/test/passing/tests/comments_args.ml.ref +++ b/test/passing/tests/comments_args.ml.ref @@ -8,7 +8,8 @@ let emit_wrapper_function = false (* is_pair_generator *) hoisted true (* no_injection *) true (* inout_wrapper *) - is_interceptable false (* is_memoize_impl *) + is_interceptable false + (* is_memoize_impl *) Rx.NonRx false [@@@ocamlformat "wrap-fun-args=false"] diff --git a/test/passing/tests/extensions-indent.ml.ref b/test/passing/tests/extensions-indent.ml.ref index 7b730b8c8a..dec5ab6dba 100644 --- a/test/passing/tests/extensions-indent.ml.ref +++ b/test/passing/tests/extensions-indent.ml.ref @@ -124,7 +124,10 @@ let _ = try%lwt Lwt.return 2 with _ -> assert false let _ = (* foooooooooooo *) - try%lwt (* fooooooooooo *) Lwt.return 2 with _ -> assert false + try%lwt + (* fooooooooooo *) + Lwt.return 2 + with _ -> assert false let _ = try%lwt diff --git a/test/passing/tests/extensions.ml.ref b/test/passing/tests/extensions.ml.ref index 3dbe10d019..b85bc9347a 100644 --- a/test/passing/tests/extensions.ml.ref +++ b/test/passing/tests/extensions.ml.ref @@ -124,7 +124,10 @@ let _ = try%lwt Lwt.return 2 with _ -> assert false let _ = (* foooooooooooo *) - try%lwt (* fooooooooooo *) Lwt.return 2 with _ -> assert false + try%lwt + (* fooooooooooo *) + Lwt.return 2 + with _ -> assert false let _ = try%lwt diff --git a/test/passing/tests/extensions_exp_grouping.ml.ref b/test/passing/tests/extensions_exp_grouping.ml.ref index fce0eb2d43..9e24406aeb 100644 --- a/test/passing/tests/extensions_exp_grouping.ml.ref +++ b/test/passing/tests/extensions_exp_grouping.ml.ref @@ -76,5 +76,8 @@ let a = (* test *) Lwt.return () ;%lwt Lwt.return 1 -let a = f ((* test *) - Lwt.return () ;%lwt Lwt.return 1) +let a = + f + ( (* test *) + Lwt.return () ;%lwt + Lwt.return 1 ) diff --git a/test/passing/tests/ite-compact.ml.ref b/test/passing/tests/ite-compact.ml.ref index 2f87f95266..a94a182514 100644 --- a/test/passing/tests/ite-compact.ml.ref +++ b/test/passing/tests/ite-compact.ml.ref @@ -119,9 +119,11 @@ let foo = let foo = if cmp < 0 then (* foo *) a + b else (* foo *) a - b let foo = - if cmp < 0 then (* ast higher precedence than context: no parens *) + if cmp < 0 then + (* ast higher precedence than context: no parens *) false - else if cmp > 0 then (* context higher prec than ast: add parens *) + else if cmp > 0 then + (* context higher prec than ast: add parens *) true else if Poly.(assoc_of_prec prec_ast = which_child && which_child <> Non) then foo @@ -138,6 +140,13 @@ let _ = else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz -let _ = if (* foo *) - foo then 0 else if (* bar *) - bar then 1 else 2 +let _ = + if + (* foo *) + foo + then 0 + else if + (* bar *) + bar + then 1 + else 2 diff --git a/test/passing/tests/ite-compact_closing.ml.ref b/test/passing/tests/ite-compact_closing.ml.ref index eb3741166d..ac36e15e6b 100644 --- a/test/passing/tests/ite-compact_closing.ml.ref +++ b/test/passing/tests/ite-compact_closing.ml.ref @@ -134,9 +134,11 @@ let foo = let foo = if cmp < 0 then (* foo *) a + b else (* foo *) a - b let foo = - if cmp < 0 then (* ast higher precedence than context: no parens *) + if cmp < 0 then + (* ast higher precedence than context: no parens *) false - else if cmp > 0 then (* context higher prec than ast: add parens *) + else if cmp > 0 then + (* context higher prec than ast: add parens *) true else if Poly.(assoc_of_prec prec_ast = which_child && which_child <> Non) then foo @@ -153,6 +155,13 @@ let _ = else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz -let _ = if (* foo *) - foo then 0 else if (* bar *) - bar then 1 else 2 +let _ = + if + (* foo *) + foo + then 0 + else if + (* bar *) + bar + then 1 + else 2 diff --git a/test/passing/tests/ite-fit_or_vertical.ml.ref b/test/passing/tests/ite-fit_or_vertical.ml.ref index b4053d7e8e..94232e3acb 100644 --- a/test/passing/tests/ite-fit_or_vertical.ml.ref +++ b/test/passing/tests/ite-fit_or_vertical.ml.ref @@ -170,11 +170,15 @@ let _ = xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = - if (* foo *) - foo then + if + (* foo *) + foo + then 0 - else if (* bar *) - bar then + else if + (* bar *) + bar + then 1 else 2 diff --git a/test/passing/tests/ite-fit_or_vertical_closing.ml.ref b/test/passing/tests/ite-fit_or_vertical_closing.ml.ref index 55cfb2e4bc..10c038c088 100644 --- a/test/passing/tests/ite-fit_or_vertical_closing.ml.ref +++ b/test/passing/tests/ite-fit_or_vertical_closing.ml.ref @@ -182,11 +182,15 @@ let _ = xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = - if (* foo *) - foo then + if + (* foo *) + foo + then 0 - else if (* bar *) - bar then + else if + (* bar *) + bar + then 1 else 2 diff --git a/test/passing/tests/ite-fit_or_vertical_no_indicate.ml.ref b/test/passing/tests/ite-fit_or_vertical_no_indicate.ml.ref index 9ec03f6d2c..116a182dd1 100644 --- a/test/passing/tests/ite-fit_or_vertical_no_indicate.ml.ref +++ b/test/passing/tests/ite-fit_or_vertical_no_indicate.ml.ref @@ -170,11 +170,15 @@ let _ = xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = - if (* foo *) - foo then + if + (* foo *) + foo + then 0 - else if (* bar *) - bar then + else if + (* bar *) + bar + then 1 else 2 diff --git a/test/passing/tests/ite-kr.ml.ref b/test/passing/tests/ite-kr.ml.ref index 20f7008a91..91a8ef6169 100644 --- a/test/passing/tests/ite-kr.ml.ref +++ b/test/passing/tests/ite-kr.ml.ref @@ -205,11 +205,15 @@ let _ = xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = - if (* foo *) - foo then + if + (* foo *) + foo + then 0 - else if (* bar *) - bar then + else if + (* bar *) + bar + then 1 else 2 diff --git a/test/passing/tests/ite-kr_closing.ml.ref b/test/passing/tests/ite-kr_closing.ml.ref index 6289345dfd..a06dc4919c 100644 --- a/test/passing/tests/ite-kr_closing.ml.ref +++ b/test/passing/tests/ite-kr_closing.ml.ref @@ -215,11 +215,15 @@ let _ = xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = - if (* foo *) - foo then + if + (* foo *) + foo + then 0 - else if (* bar *) - bar then + else if + (* bar *) + bar + then 1 else 2 diff --git a/test/passing/tests/ite-kw_first.ml.ref b/test/passing/tests/ite-kw_first.ml.ref index 20cdd01137..c3a401fa21 100644 --- a/test/passing/tests/ite-kw_first.ml.ref +++ b/test/passing/tests/ite-kw_first.ml.ref @@ -135,10 +135,12 @@ let foo = if cmp < 0 then (* foo *) a + b else (* foo *) a - b let foo = if cmp < 0 - then (* ast higher precedence than context: no parens *) + then + (* ast higher precedence than context: no parens *) false else if cmp > 0 - then (* context higher prec than ast: add parens *) + then + (* context higher prec than ast: add parens *) true else if Poly.(assoc_of_prec prec_ast = which_child && which_child <> Non) then foo @@ -161,6 +163,11 @@ let _ = fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz -let _ = if (* foo *) - foo then 0 else if (* bar *) - bar then 1 else 2 +let _ = + if (* foo *) + foo + then 0 + else if (* bar *) + bar + then 1 + else 2 diff --git a/test/passing/tests/ite-kw_first_closing.ml.ref b/test/passing/tests/ite-kw_first_closing.ml.ref index 890d3d087e..422cec07b1 100644 --- a/test/passing/tests/ite-kw_first_closing.ml.ref +++ b/test/passing/tests/ite-kw_first_closing.ml.ref @@ -150,10 +150,12 @@ let foo = if cmp < 0 then (* foo *) a + b else (* foo *) a - b let foo = if cmp < 0 - then (* ast higher precedence than context: no parens *) + then + (* ast higher precedence than context: no parens *) false else if cmp > 0 - then (* context higher prec than ast: add parens *) + then + (* context higher prec than ast: add parens *) true else if Poly.(assoc_of_prec prec_ast = which_child && which_child <> Non) then foo @@ -176,6 +178,11 @@ let _ = fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz -let _ = if (* foo *) - foo then 0 else if (* bar *) - bar then 1 else 2 +let _ = + if (* foo *) + foo + then 0 + else if (* bar *) + bar + then 1 + else 2 diff --git a/test/passing/tests/ite-kw_first_no_indicate.ml.ref b/test/passing/tests/ite-kw_first_no_indicate.ml.ref index e1cafcd1bc..d0b1ce402b 100644 --- a/test/passing/tests/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/tests/ite-kw_first_no_indicate.ml.ref @@ -134,10 +134,12 @@ let foo = if cmp < 0 then (* foo *) a + b else (* foo *) a - b let foo = if cmp < 0 - then (* ast higher precedence than context: no parens *) + then + (* ast higher precedence than context: no parens *) false else if cmp > 0 - then (* context higher prec than ast: add parens *) + then + (* context higher prec than ast: add parens *) true else if Poly.(assoc_of_prec prec_ast = which_child && which_child <> Non) then foo @@ -160,6 +162,11 @@ let _ = fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz -let _ = if (* foo *) - foo then 0 else if (* bar *) - bar then 1 else 2 +let _ = + if (* foo *) + foo + then 0 + else if (* bar *) + bar + then 1 + else 2 diff --git a/test/passing/tests/ite-no_indicate.ml.ref b/test/passing/tests/ite-no_indicate.ml.ref index df7bc50960..329f156775 100644 --- a/test/passing/tests/ite-no_indicate.ml.ref +++ b/test/passing/tests/ite-no_indicate.ml.ref @@ -118,9 +118,11 @@ let foo = let foo = if cmp < 0 then (* foo *) a + b else (* foo *) a - b let foo = - if cmp < 0 then (* ast higher precedence than context: no parens *) + if cmp < 0 then + (* ast higher precedence than context: no parens *) false - else if cmp > 0 then (* context higher prec than ast: add parens *) + else if cmp > 0 then + (* context higher prec than ast: add parens *) true else if Poly.(assoc_of_prec prec_ast = which_child && which_child <> Non) then foo @@ -137,6 +139,13 @@ let _ = else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz -let _ = if (* foo *) - foo then 0 else if (* bar *) - bar then 1 else 2 +let _ = + if + (* foo *) + foo + then 0 + else if + (* bar *) + bar + then 1 + else 2 diff --git a/test/passing/tests/ite-vertical.ml.ref b/test/passing/tests/ite-vertical.ml.ref index aa6d5c8c57..28b9323123 100644 --- a/test/passing/tests/ite-vertical.ml.ref +++ b/test/passing/tests/ite-vertical.ml.ref @@ -201,11 +201,15 @@ let _ = xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = - if (* foo *) - foo then + if + (* foo *) + foo + then 0 - else if (* bar *) - bar then + else if + (* bar *) + bar + then 1 else 2 diff --git a/test/passing/tests/ite.ml.ref b/test/passing/tests/ite.ml.ref index 2f87f95266..a94a182514 100644 --- a/test/passing/tests/ite.ml.ref +++ b/test/passing/tests/ite.ml.ref @@ -119,9 +119,11 @@ let foo = let foo = if cmp < 0 then (* foo *) a + b else (* foo *) a - b let foo = - if cmp < 0 then (* ast higher precedence than context: no parens *) + if cmp < 0 then + (* ast higher precedence than context: no parens *) false - else if cmp > 0 then (* context higher prec than ast: add parens *) + else if cmp > 0 then + (* context higher prec than ast: add parens *) true else if Poly.(assoc_of_prec prec_ast = which_child && which_child <> Non) then foo @@ -138,6 +140,13 @@ let _ = else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz -let _ = if (* foo *) - foo then 0 else if (* bar *) - bar then 1 else 2 +let _ = + if + (* foo *) + foo + then 0 + else if + (* bar *) + bar + then 1 + else 2 diff --git a/test/passing/tests/js_args.ml.ref b/test/passing/tests/js_args.ml.ref index cfdd91ada4..848baca151 100644 --- a/test/passing/tests/js_args.ml.ref +++ b/test/passing/tests/js_args.ml.ref @@ -58,16 +58,24 @@ let () = (* We like the indentation of most arguments, but want to get back towards the left margin in a few special cases: *) -let _ = foo (bar (fun x -> (* special: "fun _ ->" at EOL *) - baz )) +let _ = + foo + (bar (fun x -> + (* special: "fun _ ->" at EOL *) + baz ) ) (* assume no more arguments to "bar" *) let _ = foo ~a_long_field_name:(check (fun bar -> baz)) let _ = foo ~a_long_field_name:(check (fun bar -> baz)) -let _ = foo (bar (quux (fnord (fun x -> (* any depth *) - baz )) ) ) +let _ = + foo + (bar + (quux + (fnord (fun x -> + (* any depth *) + baz ) ) ) ) (* We also wanted to tweak the operator indentation, making operators like <= not special cases in contexts like this: *) diff --git a/test/passing/tests/js_record.ml.ref b/test/passing/tests/js_record.ml.ref index 05188cb8a7..7a8af871b4 100644 --- a/test/passing/tests/js_record.ml.ref +++ b/test/passing/tests/js_record.ml.ref @@ -2,13 +2,17 @@ type x = {foo: int; bar: int} let x = {x with foo= 3; bar= 5} -let x = {(* blah blah blah *) - foo= 3; bar= 5} +let x = + { (* blah blah blah *) + foo= 3 + ; bar= 5 } let x = [{x with foo= 3; bar= 5}] -let x = [{(* blah blah blah *) - foo= 3; bar= 5}] +let x = + [ { (* blah blah blah *) + foo= 3 + ; bar= 5 } ] let x = {M.x with M.foo= 3} diff --git a/test/passing/tests/js_source.ml.err b/test/passing/tests/js_source.ml.err index c6dd6784ca..131216f22f 100644 --- a/test/passing/tests/js_source.ml.err +++ b/test/passing/tests/js_source.ml.err @@ -1,6 +1,6 @@ -Warning: tests/js_source.ml:155 exceeds the margin -Warning: tests/js_source.ml:9537 exceeds the margin -Warning: tests/js_source.ml:9640 exceeds the margin -Warning: tests/js_source.ml:9699 exceeds the margin -Warning: tests/js_source.ml:9781 exceeds the margin -Warning: tests/js_source.ml:10290 exceeds the margin +Warning: tests/js_source.ml:156 exceeds the margin +Warning: tests/js_source.ml:9539 exceeds the margin +Warning: tests/js_source.ml:9643 exceeds the margin +Warning: tests/js_source.ml:9702 exceeds the margin +Warning: tests/js_source.ml:9784 exceeds the margin +Warning: tests/js_source.ml:10293 exceeds the margin diff --git a/test/passing/tests/js_source.ml.ocp b/test/passing/tests/js_source.ml.ocp index 4f4cd97249..33cd5e26da 100644 --- a/test/passing/tests/js_source.ml.ocp +++ b/test/passing/tests/js_source.ml.ocp @@ -113,7 +113,8 @@ let () = [%foo new x [@foo]]; [%foo match[@foo] () with - | [%foo? (* Pattern expressions *) + | [%foo? + (* Pattern expressions *) ((lazy x) [@foo])] -> () | [%foo? ((exception x) [@foo])] -> ()] ;; @@ -1132,7 +1133,8 @@ and ('a, 'e, 'b) ty_sum = ; sum_inj : 'c. ('b, 'c) ty_sel * 'c -> 'a } -and 'e ty_dyn = (* dynamic type *) +and 'e ty_dyn = + (* dynamic type *) | Tdyn : ('a, 'e) ty * 'a -> 'e ty_dyn and (_, _) ty_sel = @@ -9603,7 +9605,8 @@ exception Second_exception module M = struct type t - [@@immediate] (* ______________________________________ *) + [@@immediate] + (* ______________________________________ *) [@@deriving variants, sexp_of] end diff --git a/test/passing/tests/js_source.ml.ref b/test/passing/tests/js_source.ml.ref index 1dce6ecd6c..1d8b14768b 100644 --- a/test/passing/tests/js_source.ml.ref +++ b/test/passing/tests/js_source.ml.ref @@ -113,7 +113,8 @@ let () = [%foo new x [@foo]]; [%foo match[@foo] () with - | [%foo? (* Pattern expressions *) + | [%foo? + (* Pattern expressions *) ((lazy x) [@foo])] -> () | [%foo? ((exception x) [@foo])] -> ()] ;; @@ -1132,7 +1133,8 @@ and ('a, 'e, 'b) ty_sum = ; sum_inj : 'c. ('b, 'c) ty_sel * 'c -> 'a } -and 'e ty_dyn = (* dynamic type *) +and 'e ty_dyn = + (* dynamic type *) | Tdyn : ('a, 'e) ty * 'a -> 'e ty_dyn and (_, _) ty_sel = @@ -9603,7 +9605,8 @@ exception Second_exception module M = struct type t - [@@immediate] (* ______________________________________ *) + [@@immediate] + (* ______________________________________ *) [@@deriving variants, sexp_of] end diff --git a/test/passing/tests/let_module-sparse.ml.ref b/test/passing/tests/let_module-sparse.ml.ref index 66a42f904a..ecf801e276 100644 --- a/test/passing/tests/let_module-sparse.ml.ref +++ b/test/passing/tests/let_module-sparse.ml.ref @@ -57,5 +57,6 @@ let () = let f () = let module (* comment *) - M = struct end in + M = + struct end in () diff --git a/test/passing/tests/let_module.ml.ref b/test/passing/tests/let_module.ml.ref index e484db2ded..4489831d7d 100644 --- a/test/passing/tests/let_module.ml.ref +++ b/test/passing/tests/let_module.ml.ref @@ -49,5 +49,6 @@ let () = let f () = let module (* comment *) - M = struct end in + M = + struct end in () diff --git a/test/passing/tests/module.ml b/test/passing/tests/module.ml index 778a4ff22b..dc17ec0112 100644 --- a/test/passing/tests/module.ml +++ b/test/passing/tests/module.ml @@ -111,9 +111,11 @@ let _ = let module M = ( val (* aa *) m (* bb *) : (* cc *) - M with type t = t (* dd *) + M + with type t = t (* dd *) :> (* ee *) - N with type t = t (* ff *) ) + N + with type t = t (* ff *) ) in () diff --git a/test/passing/tests/revapply_ext.ml b/test/passing/tests/revapply_ext.ml index e3c0f4ce92..84ad583dbb 100644 --- a/test/passing/tests/revapply_ext.ml +++ b/test/passing/tests/revapply_ext.ml @@ -1,7 +1,8 @@ -let _ = () - (* one *) - |> - [%ext fun _ -> ()] +let _ = + () + (* one *) + |> + [%ext fun _ -> ()] let _ = () |> diff --git a/test/passing/tests/shortcut_ext_attr.ml b/test/passing/tests/shortcut_ext_attr.ml index 9707c46aed..01bfe49f8e 100644 --- a/test/passing/tests/shortcut_ext_attr.ml +++ b/test/passing/tests/shortcut_ext_attr.ml @@ -29,8 +29,11 @@ let () = [%foo new x [@foo]] ; [%foo match[@foo] () with - | [%foo? (* Pattern expressions *) - ((lazy x) [@foo])] -> () + | [%foo? + (* Pattern expressions *) + ((lazy x) + [@foo] )] -> + () | [%foo? ((exception x) [@foo])] -> ()] (* Class expressions *) diff --git a/test/passing/tests/source.ml.err b/test/passing/tests/source.ml.err index 50f7e55a5d..2f5951dd3e 100644 --- a/test/passing/tests/source.ml.err +++ b/test/passing/tests/source.ml.err @@ -1,2 +1,2 @@ -Warning: tests/source.ml:702 exceeds the margin -Warning: tests/source.ml:2318 exceeds the margin +Warning: tests/source.ml:705 exceeds the margin +Warning: tests/source.ml:2322 exceeds the margin diff --git a/test/passing/tests/source.ml.ref b/test/passing/tests/source.ml.ref index 8ffdea57f5..a9ed012b4d 100644 --- a/test/passing/tests/source.ml.ref +++ b/test/passing/tests/source.ml.ref @@ -127,8 +127,11 @@ let () = [%foo new x [@foo]] ; [%foo match[@foo] () with - | [%foo? (* Pattern expressions *) - ((lazy x) [@foo])] -> () + | [%foo? + (* Pattern expressions *) + ((lazy x) + [@foo] )] -> + () | [%foo? ((exception x) [@foo])] -> ()] (* Class expressions *) @@ -1185,7 +1188,8 @@ and ('a, 'e, 'b) ty_sum = ; sum_cases: (string * ('e, 'b) ty_case) list ; sum_inj: 'c. ('b, 'c) ty_sel * 'c -> 'a } -and 'e ty_dyn = (* dynamic type *) +and 'e ty_dyn = + (* dynamic type *) | Tdyn : ('a, 'e) ty * 'a -> 'e ty_dyn and (_, _) ty_sel = From 890ebb324b044c15fa002393222ad0eec2af2cd8 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 11 Jan 2024 16:34:41 +0100 Subject: [PATCH 03/10] Update CHANGES --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 50eb3c2ea7..d61493a68a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -30,6 +30,7 @@ profile. This started with version 0.26.0. - \* Force a break around comments following an infix operator (fix non-stabilizing comments) (#2478, @gpetiot) - \* Fix the indentation of tuples in attributes and extensions (#2488, @Julow) - Fix unstable comment around docked functor argument (#2506, @Julow) +- Fix unwanted alignment after comment (#2507, @Julow) ## 0.26.1 (2023-09-15) From ed6a4cb71f14547cf4803ff6c8446b9cc6586ab1 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 11 Jan 2024 16:44:04 +0100 Subject: [PATCH 04/10] Fix regression with comment in `let module M =` --- lib/Fmt_ast.ml | 9 +++++---- test/passing/tests/let_module-sparse.ml.ref | 18 ++++++++++++++++-- test/passing/tests/let_module.ml | 12 ++++++++++++ test/passing/tests/let_module.ml.ref | 18 ++++++++++++++++-- 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index a2e9d2ce23..2ca5993ddc 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -3868,10 +3868,11 @@ and fmt_module c ctx ?rec_ ?epi ?(can_sparse = false) keyword ?(eqty = "=") ~fit:true attrs in let intro = - str keyword - $ fmt_extension_suffix c ext - $ fmt_attributes c ~pre:(Break (1, 0)) attrs_before - $ fmt_if rec_flag " rec" $ str " " $ fmt_str_loc_opt c name + hvbox 2 + ( str keyword + $ fmt_extension_suffix c ext + $ fmt_attributes c ~pre:(Break (1, 0)) attrs_before + $ fmt_if rec_flag " rec" $ fmt "@ " $ fmt_str_loc_opt c name ) in let compact = Poly.(c.conf.fmt_opts.let_module.v = `Compact) || not can_sparse diff --git a/test/passing/tests/let_module-sparse.ml.ref b/test/passing/tests/let_module-sparse.ml.ref index ecf801e276..225ce4e31e 100644 --- a/test/passing/tests/let_module-sparse.ml.ref +++ b/test/passing/tests/let_module-sparse.ml.ref @@ -56,7 +56,21 @@ let () = foo let f () = - let module (* comment *) - M = + let module (* comment *) M = struct end in + () + +let f () = + let module + (* comment *) + M = + struct end in + () + +let f () = + let module + (* multi-line + + comment *) + M = struct end in () diff --git a/test/passing/tests/let_module.ml b/test/passing/tests/let_module.ml index d4f82cc14b..319e291a4b 100644 --- a/test/passing/tests/let_module.ml +++ b/test/passing/tests/let_module.ml @@ -48,7 +48,19 @@ let () = in foo +let f () = + let module (* comment *) M = struct end in + () + let f () = let module (* comment *) M = struct end in () + +let f () = + let module + (* multi-line + + comment *) + M = struct end in + () diff --git a/test/passing/tests/let_module.ml.ref b/test/passing/tests/let_module.ml.ref index 4489831d7d..08a236e77a 100644 --- a/test/passing/tests/let_module.ml.ref +++ b/test/passing/tests/let_module.ml.ref @@ -48,7 +48,21 @@ let () = foo let f () = - let module (* comment *) - M = + let module (* comment *) M = struct end in + () + +let f () = + let module + (* comment *) + M = + struct end in + () + +let f () = + let module + (* multi-line + + comment *) + M = struct end in () From 08934b4ef5bb1a5709686fb9badf2fe5ddadba42 Mon Sep 17 00:00:00 2001 From: Guillaume Petiot Date: Tue, 16 Jan 2024 10:31:32 +0100 Subject: [PATCH 05/10] Add missing break after if-then-else keyword --- lib/Params.ml | 4 +--- test/passing/tests/ite-kw_first.ml.ref | 15 +++++++++------ test/passing/tests/ite-kw_first_closing.ml.ref | 15 +++++++++------ .../passing/tests/ite-kw_first_no_indicate.ml.ref | 15 +++++++++------ 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/lib/Params.ml b/lib/Params.ml index 62698e9077..d428c29ff8 100644 --- a/lib/Params.ml +++ b/lib/Params.ml @@ -598,9 +598,7 @@ let get_if_then_else (c : Conf.t) ~first ~last ~parens_bch ~parens_prev_bch ( fmt_or_k first (str "if" $ fmt_opt fmt_extension_suffix) (str "else if") - $ fmt_attributes - $ fmt_or (Option.is_some fmt_extension_suffix) "@ " " " - $ fmt_cond xcnd ) + $ fmt_attributes $ fmt "@ " $ fmt_cond xcnd ) $ fmt "@ " ) ; box_keyword_and_expr= (fun k -> hvbox 2 (fmt_or (Option.is_some xcond) "then" "else" $ k)) diff --git a/test/passing/tests/ite-kw_first.ml.ref b/test/passing/tests/ite-kw_first.ml.ref index c3a401fa21..9e06336d81 100644 --- a/test/passing/tests/ite-kw_first.ml.ref +++ b/test/passing/tests/ite-kw_first.ml.ref @@ -45,8 +45,9 @@ f ;; f - ( if and_ even - loooooooooooooooooooooooooooooooooooooooooooooooooooooooooonger + ( if + and_ even + loooooooooooooooooooooooooooooooooooooooooooooooooooooooooonger then () else () ) @@ -164,10 +165,12 @@ let _ = xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = - if (* foo *) - foo + if + (* foo *) + foo then 0 - else if (* bar *) - bar + else if + (* bar *) + bar then 1 else 2 diff --git a/test/passing/tests/ite-kw_first_closing.ml.ref b/test/passing/tests/ite-kw_first_closing.ml.ref index 422cec07b1..64d1228d79 100644 --- a/test/passing/tests/ite-kw_first_closing.ml.ref +++ b/test/passing/tests/ite-kw_first_closing.ml.ref @@ -52,8 +52,9 @@ f ;; f - ( if and_ even - loooooooooooooooooooooooooooooooooooooooooooooooooooooooooonger + ( if + and_ even + loooooooooooooooooooooooooooooooooooooooooooooooooooooooooonger then () else () ) @@ -179,10 +180,12 @@ let _ = xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = - if (* foo *) - foo + if + (* foo *) + foo then 0 - else if (* bar *) - bar + else if + (* bar *) + bar then 1 else 2 diff --git a/test/passing/tests/ite-kw_first_no_indicate.ml.ref b/test/passing/tests/ite-kw_first_no_indicate.ml.ref index d0b1ce402b..ba802a60a0 100644 --- a/test/passing/tests/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/tests/ite-kw_first_no_indicate.ml.ref @@ -45,8 +45,9 @@ f ;; f - (if and_ even - loooooooooooooooooooooooooooooooooooooooooooooooooooooooooonger + (if + and_ even + loooooooooooooooooooooooooooooooooooooooooooooooooooooooooonger then () else ()) @@ -163,10 +164,12 @@ let _ = xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = - if (* foo *) - foo + if + (* foo *) + foo then 0 - else if (* bar *) - bar + else if + (* bar *) + bar then 1 else 2 From e48950f92996aa742e82bf68d5d362e9425c24ed Mon Sep 17 00:00:00 2001 From: Guillaume Petiot Date: Tue, 16 Jan 2024 10:35:14 +0100 Subject: [PATCH 06/10] Fix box within if-then-else branch --- lib/Params.ml | 2 +- test/passing/tests/exp_grouping.ml.ref | 4 ++-- test/passing/tests/ite-kw_first.ml.ref | 4 ++-- test/passing/tests/ite-kw_first_closing.ml.ref | 4 ++-- test/passing/tests/ite-kw_first_no_indicate.ml.ref | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/Params.ml b/lib/Params.ml index d428c29ff8..d20fcff66b 100644 --- a/lib/Params.ml +++ b/lib/Params.ml @@ -608,7 +608,7 @@ let get_if_then_else (c : Conf.t) ~first ~last ~parens_bch ~parens_prev_bch ~wrap_breaks: (get_parens_breaks ~opn_hint_indent:0 ~cls_hint:((1, 0), (1000, -2)) ) - ; box_expr= Some false + ; box_expr= None ; expr_pro= None ; expr_eol= None ; branch_expr diff --git a/test/passing/tests/exp_grouping.ml.ref b/test/passing/tests/exp_grouping.ml.ref index 14493e5665..0de0c6941b 100644 --- a/test/passing/tests/exp_grouping.ml.ref +++ b/test/passing/tests/exp_grouping.ml.ref @@ -279,8 +279,8 @@ let _ = let () = if a - then begin b - (* asd *) + then begin + b (* asd *) end [@@@ocamlformat "if-then-else=k-r"] diff --git a/test/passing/tests/ite-kw_first.ml.ref b/test/passing/tests/ite-kw_first.ml.ref index 9e06336d81..e1a2cc0640 100644 --- a/test/passing/tests/ite-kw_first.ml.ref +++ b/test/passing/tests/ite-kw_first.ml.ref @@ -159,10 +159,10 @@ let _ = if x then fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> - xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> - xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = if diff --git a/test/passing/tests/ite-kw_first_closing.ml.ref b/test/passing/tests/ite-kw_first_closing.ml.ref index 64d1228d79..53f5faa855 100644 --- a/test/passing/tests/ite-kw_first_closing.ml.ref +++ b/test/passing/tests/ite-kw_first_closing.ml.ref @@ -174,10 +174,10 @@ let _ = if x then fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> - xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> - xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = if diff --git a/test/passing/tests/ite-kw_first_no_indicate.ml.ref b/test/passing/tests/ite-kw_first_no_indicate.ml.ref index ba802a60a0..9afc0df724 100644 --- a/test/passing/tests/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/tests/ite-kw_first_no_indicate.ml.ref @@ -158,10 +158,10 @@ let _ = if x then fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> - xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> - xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = if From cea6493db5640d311542d788295c8cad42ec2b74 Mon Sep 17 00:00:00 2001 From: Guillaume Petiot Date: Tue, 16 Jan 2024 10:51:30 +0100 Subject: [PATCH 07/10] Wrap module type constraints --- lib/Fmt_ast.ml | 2 +- test/passing/tests/module.ml | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index 2ca5993ddc..e0d6326c5f 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -4189,7 +4189,7 @@ and fmt_module_expr ?(dock_struct = true) c ({ast= m; _} as xmod) = | Pmod_unpack (e, ty1, ty2) -> let package_type sep (lid, cstrs) = break 1 (Params.Indent.mod_unpack_annot c.conf) - $ hvbox 0 + $ hovbox 0 ( hovbox 0 (str sep $ fmt_longident_loc c lid) $ fmt_package_type c ctx cstrs ) in diff --git a/test/passing/tests/module.ml b/test/passing/tests/module.ml index dc17ec0112..778a4ff22b 100644 --- a/test/passing/tests/module.ml +++ b/test/passing/tests/module.ml @@ -111,11 +111,9 @@ let _ = let module M = ( val (* aa *) m (* bb *) : (* cc *) - M - with type t = t (* dd *) + M with type t = t (* dd *) :> (* ee *) - N - with type t = t (* ff *) ) + N with type t = t (* ff *) ) in () From f72186083277aa21e7972beb10a718d996701cfe Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Tue, 16 Jan 2024 14:56:28 +0100 Subject: [PATCH 08/10] Mark as breaking change --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index d61493a68a..18c1a89b8f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -30,7 +30,7 @@ profile. This started with version 0.26.0. - \* Force a break around comments following an infix operator (fix non-stabilizing comments) (#2478, @gpetiot) - \* Fix the indentation of tuples in attributes and extensions (#2488, @Julow) - Fix unstable comment around docked functor argument (#2506, @Julow) -- Fix unwanted alignment after comment (#2507, @Julow) +- \* Fix unwanted alignment after comment (#2507, @Julow) ## 0.26.1 (2023-09-15) From bb48a96c682d06fdb5b21680e49e6dd4b7c8f373 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Tue, 16 Jan 2024 14:57:03 +0100 Subject: [PATCH 09/10] Revert "Fix box within if-then-else branch" This reverts commit e48950f92996aa742e82bf68d5d362e9425c24ed. --- lib/Params.ml | 2 +- test/passing/tests/exp_grouping.ml.ref | 4 ++-- test/passing/tests/ite-kw_first.ml.ref | 4 ++-- test/passing/tests/ite-kw_first_closing.ml.ref | 4 ++-- test/passing/tests/ite-kw_first_no_indicate.ml.ref | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/Params.ml b/lib/Params.ml index d20fcff66b..d428c29ff8 100644 --- a/lib/Params.ml +++ b/lib/Params.ml @@ -608,7 +608,7 @@ let get_if_then_else (c : Conf.t) ~first ~last ~parens_bch ~parens_prev_bch ~wrap_breaks: (get_parens_breaks ~opn_hint_indent:0 ~cls_hint:((1, 0), (1000, -2)) ) - ; box_expr= None + ; box_expr= Some false ; expr_pro= None ; expr_eol= None ; branch_expr diff --git a/test/passing/tests/exp_grouping.ml.ref b/test/passing/tests/exp_grouping.ml.ref index 0de0c6941b..14493e5665 100644 --- a/test/passing/tests/exp_grouping.ml.ref +++ b/test/passing/tests/exp_grouping.ml.ref @@ -279,8 +279,8 @@ let _ = let () = if a - then begin - b (* asd *) + then begin b + (* asd *) end [@@@ocamlformat "if-then-else=k-r"] diff --git a/test/passing/tests/ite-kw_first.ml.ref b/test/passing/tests/ite-kw_first.ml.ref index e1a2cc0640..9e06336d81 100644 --- a/test/passing/tests/ite-kw_first.ml.ref +++ b/test/passing/tests/ite-kw_first.ml.ref @@ -159,10 +159,10 @@ let _ = if x then fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> - xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> - xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = if diff --git a/test/passing/tests/ite-kw_first_closing.ml.ref b/test/passing/tests/ite-kw_first_closing.ml.ref index 53f5faa855..64d1228d79 100644 --- a/test/passing/tests/ite-kw_first_closing.ml.ref +++ b/test/passing/tests/ite-kw_first_closing.ml.ref @@ -174,10 +174,10 @@ let _ = if x then fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> - xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> - xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = if diff --git a/test/passing/tests/ite-kw_first_no_indicate.ml.ref b/test/passing/tests/ite-kw_first_no_indicate.ml.ref index 9afc0df724..ba802a60a0 100644 --- a/test/passing/tests/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/tests/ite-kw_first_no_indicate.ml.ref @@ -158,10 +158,10 @@ let _ = if x then fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> - xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz else fun xxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyy zzzzzzzzzzz -> - xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz + xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = if From b8cb6c330011aecba5115a4b23808f4a2264d1c2 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Tue, 16 Jan 2024 14:57:14 +0100 Subject: [PATCH 10/10] Revert "Add missing break after if-then-else keyword" This reverts commit 08934b4ef5bb1a5709686fb9badf2fe5ddadba42. --- lib/Params.ml | 4 +++- test/passing/tests/ite-kw_first.ml.ref | 15 ++++++--------- test/passing/tests/ite-kw_first_closing.ml.ref | 15 ++++++--------- .../passing/tests/ite-kw_first_no_indicate.ml.ref | 15 ++++++--------- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/lib/Params.ml b/lib/Params.ml index d428c29ff8..62698e9077 100644 --- a/lib/Params.ml +++ b/lib/Params.ml @@ -598,7 +598,9 @@ let get_if_then_else (c : Conf.t) ~first ~last ~parens_bch ~parens_prev_bch ( fmt_or_k first (str "if" $ fmt_opt fmt_extension_suffix) (str "else if") - $ fmt_attributes $ fmt "@ " $ fmt_cond xcnd ) + $ fmt_attributes + $ fmt_or (Option.is_some fmt_extension_suffix) "@ " " " + $ fmt_cond xcnd ) $ fmt "@ " ) ; box_keyword_and_expr= (fun k -> hvbox 2 (fmt_or (Option.is_some xcond) "then" "else" $ k)) diff --git a/test/passing/tests/ite-kw_first.ml.ref b/test/passing/tests/ite-kw_first.ml.ref index 9e06336d81..c3a401fa21 100644 --- a/test/passing/tests/ite-kw_first.ml.ref +++ b/test/passing/tests/ite-kw_first.ml.ref @@ -45,9 +45,8 @@ f ;; f - ( if - and_ even - loooooooooooooooooooooooooooooooooooooooooooooooooooooooooonger + ( if and_ even + loooooooooooooooooooooooooooooooooooooooooooooooooooooooooonger then () else () ) @@ -165,12 +164,10 @@ let _ = xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = - if - (* foo *) - foo + if (* foo *) + foo then 0 - else if - (* bar *) - bar + else if (* bar *) + bar then 1 else 2 diff --git a/test/passing/tests/ite-kw_first_closing.ml.ref b/test/passing/tests/ite-kw_first_closing.ml.ref index 64d1228d79..422cec07b1 100644 --- a/test/passing/tests/ite-kw_first_closing.ml.ref +++ b/test/passing/tests/ite-kw_first_closing.ml.ref @@ -52,9 +52,8 @@ f ;; f - ( if - and_ even - loooooooooooooooooooooooooooooooooooooooooooooooooooooooooonger + ( if and_ even + loooooooooooooooooooooooooooooooooooooooooooooooooooooooooonger then () else () ) @@ -180,12 +179,10 @@ let _ = xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = - if - (* foo *) - foo + if (* foo *) + foo then 0 - else if - (* bar *) - bar + else if (* bar *) + bar then 1 else 2 diff --git a/test/passing/tests/ite-kw_first_no_indicate.ml.ref b/test/passing/tests/ite-kw_first_no_indicate.ml.ref index ba802a60a0..d0b1ce402b 100644 --- a/test/passing/tests/ite-kw_first_no_indicate.ml.ref +++ b/test/passing/tests/ite-kw_first_no_indicate.ml.ref @@ -45,9 +45,8 @@ f ;; f - (if - and_ even - loooooooooooooooooooooooooooooooooooooooooooooooooooooooooonger + (if and_ even + loooooooooooooooooooooooooooooooooooooooooooooooooooooooooonger then () else ()) @@ -164,12 +163,10 @@ let _ = xxxxxxxxx yyyyyyyyyy zzzzzzzzzzzz let _ = - if - (* foo *) - foo + if (* foo *) + foo then 0 - else if - (* bar *) - bar + else if (* bar *) + bar then 1 else 2