Skip to content

Commit 96cc58c

Browse files
authored
Fix dropped comment in (function _ -> x (* cmt *)) (#2739)
1 parent 809492a commit 96cc58c

File tree

7 files changed

+44
-2
lines changed

7 files changed

+44
-2
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Items marked with an asterisk (\*) are changes that are likely to format
44
existing code differently from the previous release when using the default
55
profile. This started with version 0.26.0.
66

7+
## unreleased
8+
9+
### Fixed
10+
11+
- Fix dropped comment in `(function _ -> x (* cmt *))` (#2739, @Julow)
12+
713
## 0.28.1
814

915
### Highlight

lib/Fmt_ast.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,7 @@ and fmt_function ?force_closing_paren ~ctx ~ctx0 ?pro ~wrap_intro
16331633
in
16341634
fmt_infix_ext_attrs c ~pro:function_ infix_ext_attrs
16351635
in
1636+
let cmt_after_cases = Cmts.fmt_after c function_loc in
16361637
let box_cases ~pro cases =
16371638
let pro_inner, pro_outer, indent =
16381639
(* Formatting of if-then-else relies on the ~box argument. *)
@@ -1653,8 +1654,9 @@ and fmt_function ?force_closing_paren ~ctx ~ctx0 ?pro ~wrap_intro
16531654
( fmt_pattern c ~pro:(if_newline "| ") (sub_pat ~ctx pc_lhs)
16541655
$ space_break $ str "->" )
16551656
$ space_break
1656-
$ cbox 0 (fmt_expression c (sub_exp ~ctx pc_rhs)) )
1657-
| _ -> (box, fmt_cases c ctx cs)
1657+
$ cbox 0 (fmt_expression c (sub_exp ~ctx pc_rhs))
1658+
$ cmt_after_cases )
1659+
| _ -> (box, fmt_cases c ctx cs $ cmt_after_cases)
16581660
in
16591661
(fun_ $ function_, box_cases cases, box, 0)
16601662
in

test/passing/refs.ahrefs/fun_function.ml.ref

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,9 @@ let f = function
179179
| ElementHole -> ElementHole
180180
| Element e -> Element (m#expression e)
181181
| ElementSpread e -> ElementSpread (m#expression e)))
182+
183+
let _ =
184+
f (function _ -> x
185+
(* o::other reverses the list, in order to keep
186+
Remote and other order-sensitive stanzas intact
187+
we need to List.rev the [tl] list. *))

test/passing/refs.default/fun_function.ml.ref

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,9 @@ let f = function
146146
| ElementHole -> ElementHole
147147
| Element e -> Element (m#expression e)
148148
| ElementSpread e -> ElementSpread (m#expression e)))
149+
150+
let _ =
151+
f (function _ -> x
152+
(* o::other reverses the list, in order to keep
153+
Remote and other order-sensitive stanzas intact
154+
we need to List.rev the [tl] list. *))

test/passing/refs.janestreet/fun_function.ml.ref

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,10 @@ let f = function
223223
| Element e -> Element (m#expression e)
224224
| ElementSpread e -> ElementSpread (m#expression e)))
225225
;;
226+
227+
let _ =
228+
f (function _ -> x
229+
(* o::other reverses the list, in order to keep
230+
Remote and other order-sensitive stanzas intact
231+
we need to List.rev the [tl] list. *))
232+
;;

test/passing/refs.ocamlformat/fun_function.ml.ref

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,9 @@ let f = function
167167
Element (m#expression e)
168168
| ElementSpread e ->
169169
ElementSpread (m#expression e) ))
170+
171+
let _ =
172+
f (function _ -> x
173+
(* o::other reverses the list, in order to keep
174+
Remote and other order-sensitive stanzas intact
175+
we need to List.rev the [tl] list. *) )

test/passing/tests/fun_function.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,12 @@ let f = function
8686
| ElementHole -> ElementHole
8787
| Element e -> Element (m#expression e)
8888
| ElementSpread e -> ElementSpread (m#expression e)))
89+
90+
let _ =
91+
f
92+
(function
93+
| _ ->
94+
x
95+
(* o::other reverses the list, in order to keep
96+
Remote and other order-sensitive stanzas intact
97+
we need to List.rev the [tl] list. *))

0 commit comments

Comments
 (0)