From 792ec9cd14e55e64da2385add5ad72f41aa33f8b Mon Sep 17 00:00:00 2001 From: EmileTrotignon Date: Fri, 6 Jun 2025 17:01:38 +0200 Subject: [PATCH 1/3] fix f (g a begin end) --- lib/Fmt_ast.ml | 7 ++++--- test/passing/tests/exp_grouping.ml | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index b6961946ff..5f282f8d5a 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -2302,14 +2302,15 @@ and fmt_expression c ?(box = true) ?(pro = noop) ?eol ?parens let pro = intro_epi $ fmt_if parens (str "(") - $ ( fmt_args_grouped ~epi:fmt_atrs e0 args_before - $ fmt_if parens (closing_paren c ~force ~offset:(-3)) ) + $ fmt_args_grouped ~epi:fmt_atrs e0 args_before in let label_sep = Params.Exp.fun_label_sep c.conf in let pro = pro $ break 1 0 $ fmt_label lbl label_sep in expr_epi $ hovbox 4 - (fmt_expression c ~pro ~box:false (sub_exp ~ctx last_arg)) + (fmt_expression c ~pro ~box:false (sub_exp ~ctx last_arg) + $ fmt_if parens (closing_paren c ~force ~offset:(-3)) + ) | _ -> let fmt_atrs = fmt_attributes c ~pre:(Break (1, -2)) pexp_attributes diff --git a/test/passing/tests/exp_grouping.ml b/test/passing/tests/exp_grouping.ml index 3ff154a3ea..352b4da5f7 100644 --- a/test/passing/tests/exp_grouping.ml +++ b/test/passing/tests/exp_grouping.ml @@ -547,3 +547,10 @@ let () = in fooooooooooo x end + +let f () = + f + (g a begin fun () -> + let x = y in + z + end ) From 1f63ec77d798b4d1ad9105732c7ba92c2ac81fd1 Mon Sep 17 00:00:00 2001 From: EmileTrotignon Date: Fri, 6 Jun 2025 17:23:41 +0200 Subject: [PATCH 2/3] dune fmt --- lib/Fmt_ast.ml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index 5f282f8d5a..9c7e2c765a 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -2308,9 +2308,8 @@ and fmt_expression c ?(box = true) ?(pro = noop) ?eol ?parens let pro = pro $ break 1 0 $ fmt_label lbl label_sep in expr_epi $ hovbox 4 - (fmt_expression c ~pro ~box:false (sub_exp ~ctx last_arg) - $ fmt_if parens (closing_paren c ~force ~offset:(-3)) - ) + ( fmt_expression c ~pro ~box:false (sub_exp ~ctx last_arg) + $ fmt_if parens (closing_paren c ~force ~offset:(-3)) ) | _ -> let fmt_atrs = fmt_attributes c ~pre:(Break (1, -2)) pexp_attributes From 638ad1ddb9d5e6c22a20e9bb1209691abd9c57e3 Mon Sep 17 00:00:00 2001 From: EmileTrotignon Date: Fri, 6 Jun 2025 17:27:37 +0200 Subject: [PATCH 3/3] promote tests --- test/passing/refs.ahrefs/exp_grouping-parens.ml.ref | 6 ++++++ test/passing/refs.ahrefs/exp_grouping.ml.ref | 7 +++++++ test/passing/refs.default/exp_grouping-parens.ml.ref | 6 ++++++ test/passing/refs.default/exp_grouping.ml.ref | 7 +++++++ test/passing/refs.janestreet/exp_grouping-parens.ml.ref | 7 +++++++ test/passing/refs.janestreet/exp_grouping.ml.ref | 8 ++++++++ test/passing/refs.ocamlformat/exp_grouping-parens.ml.ref | 6 ++++++ test/passing/refs.ocamlformat/exp_grouping.ml.ref | 7 +++++++ 8 files changed, 54 insertions(+) diff --git a/test/passing/refs.ahrefs/exp_grouping-parens.ml.ref b/test/passing/refs.ahrefs/exp_grouping-parens.ml.ref index 637e743e9f..347b3fffd7 100644 --- a/test/passing/refs.ahrefs/exp_grouping-parens.ml.ref +++ b/test/passing/refs.ahrefs/exp_grouping-parens.ml.ref @@ -578,3 +578,9 @@ let () = $ y in fooooooooooo x) + +let f () = + f + (g a (fun () -> + let x = y in + z)) diff --git a/test/passing/refs.ahrefs/exp_grouping.ml.ref b/test/passing/refs.ahrefs/exp_grouping.ml.ref index 46d5ac016f..054240dbbc 100644 --- a/test/passing/refs.ahrefs/exp_grouping.ml.ref +++ b/test/passing/refs.ahrefs/exp_grouping.ml.ref @@ -662,3 +662,10 @@ let () = in fooooooooooo x end + +let f () = + f + (g a begin fun () -> + let x = y in + z + end) diff --git a/test/passing/refs.default/exp_grouping-parens.ml.ref b/test/passing/refs.default/exp_grouping-parens.ml.ref index e3a2116f50..153fb6f88d 100644 --- a/test/passing/refs.default/exp_grouping-parens.ml.ref +++ b/test/passing/refs.default/exp_grouping-parens.ml.ref @@ -595,3 +595,9 @@ let () = $ y in fooooooooooo x) + +let f () = + f + (g a (fun () -> + let x = y in + z)) diff --git a/test/passing/refs.default/exp_grouping.ml.ref b/test/passing/refs.default/exp_grouping.ml.ref index ae14a21856..c4a1afb6e9 100644 --- a/test/passing/refs.default/exp_grouping.ml.ref +++ b/test/passing/refs.default/exp_grouping.ml.ref @@ -680,3 +680,10 @@ let () = in fooooooooooo x end + +let f () = + f + (g a begin fun () -> + let x = y in + z + end) diff --git a/test/passing/refs.janestreet/exp_grouping-parens.ml.ref b/test/passing/refs.janestreet/exp_grouping-parens.ml.ref index 1fb32db250..a221769b6a 100644 --- a/test/passing/refs.janestreet/exp_grouping-parens.ml.ref +++ b/test/passing/refs.janestreet/exp_grouping-parens.ml.ref @@ -677,3 +677,10 @@ let () = in fooooooooooo x) ;; + +let f () = + f + (g a (fun () -> + let x = y in + z)) +;; diff --git a/test/passing/refs.janestreet/exp_grouping.ml.ref b/test/passing/refs.janestreet/exp_grouping.ml.ref index 2c7f825df3..f66a0f6b0d 100644 --- a/test/passing/refs.janestreet/exp_grouping.ml.ref +++ b/test/passing/refs.janestreet/exp_grouping.ml.ref @@ -765,3 +765,11 @@ let () = fooooooooooo x end ;; + +let f () = + f + (g a begin fun () -> + let x = y in + z + end) +;; diff --git a/test/passing/refs.ocamlformat/exp_grouping-parens.ml.ref b/test/passing/refs.ocamlformat/exp_grouping-parens.ml.ref index ef1b600243..8f10b4c4b1 100644 --- a/test/passing/refs.ocamlformat/exp_grouping-parens.ml.ref +++ b/test/passing/refs.ocamlformat/exp_grouping-parens.ml.ref @@ -599,3 +599,9 @@ let () = $ y in fooooooooooo x ) + +let f () = + f + (g a (fun () -> + let x = y in + z ) ) diff --git a/test/passing/refs.ocamlformat/exp_grouping.ml.ref b/test/passing/refs.ocamlformat/exp_grouping.ml.ref index ceb4118ef7..b7534ade29 100644 --- a/test/passing/refs.ocamlformat/exp_grouping.ml.ref +++ b/test/passing/refs.ocamlformat/exp_grouping.ml.ref @@ -686,3 +686,10 @@ let () = in fooooooooooo x end + +let f () = + f + (g a begin fun () -> + let x = y in + z + end )