Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unstable comment just before or-patterns #1167

Merged
merged 5 commits into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 "@ ")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pro must be noop when adj is not to avoid extra empty lines.

else (fmt "@ ", noop)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find a case where break 1000 0 was necessary.

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 _ )
} -> ()
;;