Skip to content

Commit

Permalink
Empty or singleton array/list expressions are considered "simple" (#1943
Browse files Browse the repository at this point in the history
)
  • Loading branch information
gpetiot authored Jan 18, 2022
1 parent 08ac3c3 commit 0d66622
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions lib/Ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
12 changes: 12 additions & 0 deletions test/passing/tests/js_source.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;;
10 changes: 10 additions & 0 deletions test/passing/tests/js_source.ml.ocp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;;
10 changes: 10 additions & 0 deletions test/passing/tests/js_source.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;;
4 changes: 1 addition & 3 deletions test/passing/tests/source.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 0d66622

Please sign in to comment.