diff --git a/CHANGES.md b/CHANGES.md index c8061ce90f..7f5dbbddbe 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,7 +12,9 @@ #### Changes - + Variant expressions with no argument are considered "simple" (not inducing a break e.g. as an argument of an application) (#1968, @gpetiot) + + More expressions are considered "simple" (not inducing a break e.g. as an argument of an application): + - Variants with no argument (#1968, @gpetiot) + - Empty or singleton arrays/lists (#1943, @gpetiot) + Print odoc code block delimiters on their own line (#1980, @gpetiot) diff --git a/lib/Ast.ml b/lib/Ast.ml index 595c7c9ad0..b68829e863 100644 --- a/lib/Ast.ml +++ b/lib/Ast.ml @@ -314,6 +314,8 @@ module Exp = struct ({pexp_desc= Pexp_ident {txt= Lident "not"; _}; _}, [(_, e1)]) -> is_trivial e1 | Pexp_variant (_, None) -> true + | Pexp_array [] | Pexp_list [] -> true + | Pexp_array [x] | Pexp_list [x] -> is_trivial x | _ -> false let rec exposed_left e = diff --git a/test/passing/tests/js_source.ml b/test/passing/tests/js_source.ml index 308e7d9b0f..7729f44a3a 100644 --- a/test/passing/tests/js_source.ml +++ b/test/passing/tests/js_source.ml @@ -7603,3 +7603,15 @@ let x = ~f:(fun thing -> something that reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally needs wrapping) ;; + +let x = + foo [ A; B ] ~f:(fun thing -> + something that reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally needs wrapping) +;; + +let x = + foo + [ [ A ]; B ] + ~f:(fun thing -> + something that reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally needs wrapping) +;; diff --git a/test/passing/tests/js_source.ml.ocp b/test/passing/tests/js_source.ml.ocp index 562db45678..bd43391e53 100644 --- a/test/passing/tests/js_source.ml.ocp +++ b/test/passing/tests/js_source.ml.ocp @@ -9844,3 +9844,13 @@ let x = foo (`A `b) ~f:(fun thing -> something that reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally needs wrapping) ;; + +let x = + foo [ A; B ] ~f:(fun thing -> + something that reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally needs wrapping) +;; + +let x = + foo [ [ A ]; B ] ~f:(fun thing -> + something that reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally needs wrapping) +;; diff --git a/test/passing/tests/js_source.ml.ref b/test/passing/tests/js_source.ml.ref index 847acde849..bf59261e3e 100644 --- a/test/passing/tests/js_source.ml.ref +++ b/test/passing/tests/js_source.ml.ref @@ -9844,3 +9844,13 @@ let x = foo (`A `b) ~f:(fun thing -> something that reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally needs wrapping) ;; + +let x = + foo [ A; B ] ~f:(fun thing -> + something that reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally needs wrapping) +;; + +let x = + foo [ [ A ]; B ] ~f:(fun thing -> + something that reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally needs wrapping) +;; diff --git a/test/passing/tests/source.ml.ref b/test/passing/tests/source.ml.ref index f752d76024..0f472b5991 100644 --- a/test/passing/tests/source.ml.ref +++ b/test/passing/tests/source.ml.ref @@ -8967,9 +8967,7 @@ let h ?l:(p = 1) ?y:u ?(x = 3) = 2 let _ = function | a, s, ba1, ba2, ba3, bg -> ignore - ( Array.get x 1 - + Array.get [||] 0 - + Array.get [|1|] 1 + ( Array.get x 1 + Array.get [||] 0 + Array.get [|1|] 1 + Array.get [|1; 2|] 2 ) ; ignore [String.get s 1; String.get "" 2; String.get "123" 3] ; ignore (ba1.{0} + ba2.{1, 2} + ba3.{3, 4, 5}) ignore bg.{1, 2, 3, 4}