From fd21b798e2bc58b94861aa6968b0610ae0f5e076 Mon Sep 17 00:00:00 2001 From: Guillaume Petiot Date: Thu, 9 Mar 2023 09:53:15 +0000 Subject: [PATCH] JaneStreet profile: add extra parens around tuple with type annotation (#2281) --- CHANGES.md | 2 ++ lib/Ast.ml | 15 +++++++++++++-- test/passing/tests/js_source.ml | 2 ++ test/passing/tests/js_source.ml.ocp | 5 +++++ test/passing/tests/js_source.ml.ref | 5 +++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c2f4fca25c..18fac93aa7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ ### Changes +- JaneStreet profile: add extra parens around tuple with type annotation (#2281, @gpetiot) + ### New features ## 0.25.1 (2023-03-06) diff --git a/lib/Ast.ml b/lib/Ast.ml index 86083ffaa4..c8329d1a52 100644 --- a/lib/Ast.ml +++ b/lib/Ast.ml @@ -26,20 +26,28 @@ let ( init , register_reset , leading_nested_match_parens , parens_ite - , ocaml_version ) = + , ocaml_version + , ocp_indent_compat ) = let l = ref [] in let leading_nested_match_parens = ref false in let parens_ite = ref false in let ocaml_version = ref Ocaml_version.sys_version in + let ocp_indent_compat = ref false in let register f = l := f :: !l in let init (conf : Conf.t) = leading_nested_match_parens := conf.fmt_opts.leading_nested_match_parens.v ; parens_ite := conf.fmt_opts.parens_ite.v ; ocaml_version := conf.opr_opts.ocaml_version.v ; + ocp_indent_compat := conf.fmt_opts.ocp_indent_compat.v ; List.iter !l ~f:(fun f -> f ()) in - (init, register, leading_nested_match_parens, parens_ite, ocaml_version) + ( init + , register + , leading_nested_match_parens + , parens_ite + , ocaml_version + , ocp_indent_compat ) (** [fit_margin c x] returns [true] if and only if [x] does not exceed 1/3 of the margin. *) @@ -2174,6 +2182,9 @@ end = struct | Exp {pexp_desc= Pexp_indexop_access {pia_kind= Builtin idx; _}; _}, _ when idx == exp -> false + | Exp {pexp_desc= Pexp_constraint (e, _); _}, {pexp_desc= Pexp_tuple _; _} + when e == exp && !ocp_indent_compat -> + true | ( Exp { pexp_desc= Pexp_indexop_access diff --git a/test/passing/tests/js_source.ml b/test/passing/tests/js_source.ml index 8fabdbd3c1..8b1c33a9fb 100644 --- a/test/passing/tests/js_source.ml +++ b/test/passing/tests/js_source.ml @@ -7650,3 +7650,5 @@ let () = very_long_argument_name_two very_long_argument_name_three -> () ) + +let () = ((one_mississippi, two_mississippi, three_mississippi, four_mississippi) : Mississippi.t * Mississippi.t * Mississippi.t * Mississippi.t) diff --git a/test/passing/tests/js_source.ml.ocp b/test/passing/tests/js_source.ml.ocp index fa65976d84..6c2bcf8360 100644 --- a/test/passing/tests/js_source.ml.ocp +++ b/test/passing/tests/js_source.ml.ocp @@ -9874,3 +9874,8 @@ let () = very_long_argument_name_three -> ()) ;; + +let () = + ((one_mississippi, two_mississippi, three_mississippi, four_mississippi) + : Mississippi.t * Mississippi.t * Mississippi.t * Mississippi.t) +;; diff --git a/test/passing/tests/js_source.ml.ref b/test/passing/tests/js_source.ml.ref index 9ceb09dc0b..61187567a0 100644 --- a/test/passing/tests/js_source.ml.ref +++ b/test/passing/tests/js_source.ml.ref @@ -9874,3 +9874,8 @@ let () = very_long_argument_name_three -> ()) ;; + +let () = + ((one_mississippi, two_mississippi, three_mississippi, four_mississippi) + : Mississippi.t * Mississippi.t * Mississippi.t * Mississippi.t) +;;