Skip to content

Commit

Permalink
Fix unstable comment just before or-patterns (ocaml-ppx#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julow authored and bogdan2412 committed Mar 28, 2020
1 parent e7a185c commit 3921f57
Show file tree
Hide file tree
Showing 15 changed files with 305 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

#### Bug fixes

+ Fix unstable comment in variant declarations (#1108) (Jules Aguillon)
+ Fix wrapping of or-patterns in presence of comments with `break-cases=fit` (#1167) (Jules Aguillon)
This also fixes an unstable comment bug in or-patterns
+ Fix an unstable comment bug in variant declarations (#1108) (Jules Aguillon)
+ Fix: break multiline comments (#1122) (Guillaume Petiot)
+ Fix: types on named arguments were wrapped incorrectly when preceding comments (#1124) (Guillaume Petiot)
+ Fix the indentation produced by max-indent (#1118) (Guillaume Petiot)
Expand Down
7 changes: 5 additions & 2 deletions lib/Fmt_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1031,8 +1031,11 @@ and fmt_pattern c ?pro ?parens ({ctx= ctx0; ast= pat} as xpat) =
let loc = xpat.ast.ppat_loc in
let force_break = Cmts.has_before c.cmts loc in
let leading_cmt =
Cmts.fmt_before ~pro:(Fmt.break 1000 0) ~adj:noop c loc
~eol:noop
let pro, adj =
if first_grp && first then (noop, fmt "@ ")
else (fmt "@ ", noop)
in
Cmts.fmt_before ~pro c loc ~adj ~eol:noop
in
let pro =
if first_grp && first then
Expand Down
24 changes: 24 additions & 0 deletions test/passing/break_cases-align.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,27 @@ let handler =
Errors.isset_in_strict p
| _ -> ()
end

let _ =
match abc with
| Fooooooooooooooooo
(* comment *)
| Baaaaaaaaaaaaaaaar
(* comment *)
| Baaaaaaaaaaaaaaaaz (* comment *) ->
()

let _ =
match x with
| { y=
(* _____________________________________________________________________ *)
( X _ | Y _ ) } ->
()

let _ =
match x with
| { y=
( Z
(* _____________________________________________________________________ *)
| X _ | Y _ ) } ->
()
24 changes: 24 additions & 0 deletions test/passing/break_cases-all.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,27 @@ let handler =
Errors.isset_in_strict p
| _ -> ()
end

let _ =
match abc with
| Fooooooooooooooooo
(* comment *)
| Baaaaaaaaaaaaaaaar
(* comment *)
| Baaaaaaaaaaaaaaaaz (* comment *) ->
()

let _ =
match x with
| { y=
(* _____________________________________________________________________ *)
( X _ | Y _ ) } ->
()

let _ =
match x with
| { y=
( Z
(* _____________________________________________________________________ *)
| X _ | Y _ ) } ->
()
24 changes: 24 additions & 0 deletions test/passing/break_cases-closing_on_separate_line.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,27 @@ let handler =
Errors.isset_in_strict p
| _ -> ()
end

let _ =
match abc with
| Fooooooooooooooooo
(* comment *)
| Baaaaaaaaaaaaaaaar
(* comment *)
| Baaaaaaaaaaaaaaaaz (* comment *) ->
()

let _ =
match x with
| { y=
(* _____________________________________________________________________ *)
( X _ | Y _ ) } ->
()

let _ =
match x with
| { y=
( Z
(* _____________________________________________________________________ *)
| X _ | Y _ ) } ->
()
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,27 @@ let handler =
Errors.isset_in_strict p
| _ -> ()
end

let _ =
match abc with
| Fooooooooooooooooo
(* comment *)
| Baaaaaaaaaaaaaaaar
(* comment *)
| Baaaaaaaaaaaaaaaaz (* comment *) ->
()

let _ =
match x with
| { y=
(* _____________________________________________________________________ *)
( X _ | Y _ ) } ->
()

let _ =
match x with
| { y=
( Z
(* _____________________________________________________________________ *)
| X _ | Y _ ) } ->
()
24 changes: 24 additions & 0 deletions test/passing/break_cases-cosl_lnmp_cmei.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,27 @@ let handler =
Errors.isset_in_strict p
| _ -> ()
end

let _ =
match abc with
| Fooooooooooooooooo
(* comment *)
| Baaaaaaaaaaaaaaaar
(* comment *)
| Baaaaaaaaaaaaaaaaz (* comment *) ->
()

let _ =
match x with
| { y=
(* _____________________________________________________________________ *)
( X _ | Y _ ) } ->
()

let _ =
match x with
| { y=
( Z
(* _____________________________________________________________________ *)
| X _ | Y _ ) } ->
()
23 changes: 23 additions & 0 deletions test/passing/break_cases-fit_or_vertical.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,26 @@ let handler =
| Call OtherThing -> Errors.isset_in_strict p
| _ -> ()
end

let _ =
match abc with
| Fooooooooooooooooo
(* comment *)
| Baaaaaaaaaaaaaaaar
(* comment *)
| Baaaaaaaaaaaaaaaaz
(* comment *) -> ()

let _ =
match x with
| { y=
(* _____________________________________________________________________ *)
( X _ | Y _ ) } -> ()

let _ =
match x with
| { y=
( Z
(* _____________________________________________________________________ *)
| X _
| Y _ ) } -> ()
25 changes: 25 additions & 0 deletions test/passing/break_cases-nested.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,28 @@ let handler =
| _ ->
()
end

let _ =
match abc with
| Fooooooooooooooooo (* comment *)
| Baaaaaaaaaaaaaaaar
(* comment *)
| Baaaaaaaaaaaaaaaaz (* comment *) ->
()

let _ =
match x with
| { y=
(* _____________________________________________________________________ *)
( X _
| Y _ ) } ->
()

let _ =
match x with
| { y=
( Z
(* _____________________________________________________________________ *)
| X _
| Y _ ) } ->
()
24 changes: 24 additions & 0 deletions test/passing/break_cases-normal_indent.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,27 @@ let handler =
Errors.isset_in_strict p
| _ -> ()
end

let _ =
match abc with
| Fooooooooooooooooo
(* comment *)
| Baaaaaaaaaaaaaaaar
(* comment *)
| Baaaaaaaaaaaaaaaaz (* comment *) ->
()

let _ =
match x with
| { y=
(* _____________________________________________________________________ *)
( X _ | Y _ ) } ->
()

let _ =
match x with
| { y=
( Z
(* _____________________________________________________________________ *)
| X _ | Y _ ) } ->
()
22 changes: 22 additions & 0 deletions test/passing/break_cases-toplevel.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,25 @@ let handler =
Errors.isset_in_strict p
| _ -> ()
end

let _ =
match abc with
| Fooooooooooooooooo (* comment *) | Baaaaaaaaaaaaaaaar
(* comment *)
| Baaaaaaaaaaaaaaaaz (* comment *) ->
()

let _ =
match x with
| { y=
(* _____________________________________________________________________ *)
( X _ | Y _ ) } ->
()

let _ =
match x with
| { y=
( Z
(* _____________________________________________________________________ *)
| X _ | Y _ ) } ->
()
26 changes: 26 additions & 0 deletions test/passing/break_cases.ml
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,29 @@ let handler =
Errors.isset_in_strict p
| _ -> ()
end

let _ =
match abc with
| Fooooooooooooooooo (* comment *)
| Baaaaaaaaaaaaaaaar
(* comment *)
| Baaaaaaaaaaaaaaaaz
(* comment *)
-> ()

let _ =
match x with
| { y =
(* _____________________________________________________________________ *)
( X _ | Y _ )
} -> ()
;;

let _ =
match x with
| { y =
Z |
(* _____________________________________________________________________ *)
( X _ | Y _ )
} -> ()
;;
22 changes: 22 additions & 0 deletions test/passing/break_cases.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,25 @@ let handler =
Errors.isset_in_strict p
| _ -> ()
end

let _ =
match abc with
| Fooooooooooooooooo (* comment *) | Baaaaaaaaaaaaaaaar
(* comment *)
| Baaaaaaaaaaaaaaaaz (* comment *) ->
()

let _ =
match x with
| { y=
(* _____________________________________________________________________ *)
( X _ | Y _ ) } ->
()

let _ =
match x with
| { y=
( Z
(* _____________________________________________________________________ *)
| X _ | Y _ ) } ->
()
17 changes: 17 additions & 0 deletions test/passing/js_source.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7482,3 +7482,20 @@ let f =
comment *)
~y
;;

let _ =
match x with
| { y =
(* _____________________________________________________________________ *)
( X _ | Y _ )
} -> ()
;;

let _ =
match x with
| { y =
Z |
(* _____________________________________________________________________ *)
( X _ | Y _ )
} -> ()
;;
18 changes: 18 additions & 0 deletions test/passing/js_source.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -9856,3 +9856,21 @@ let f =
comment *)
~y
;;

let _ =
match x with
| { y =
(* _____________________________________________________________________ *)
( X _ | Y _ )
} -> ()
;;

let _ =
match x with
| { y =
( Z
(* _____________________________________________________________________ *)
| X _
| Y _ )
} -> ()
;;

0 comments on commit 3921f57

Please sign in to comment.