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

Conversation

Julow
Copy link
Collaborator

@Julow Julow commented Nov 26, 2019

Fixes #1164

@Julow Julow requested a review from gpetiot November 26, 2019 17:00
@facebook-github-bot
Copy link

Hi Julow! Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file.In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

~eol:noop
let pro, adj =
if first_grp && first then (noop, fmt "@ ")
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.

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.

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

Copy link
Collaborator

@gpetiot gpetiot left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks.
For completeness, here is the diff for the conventional profile (no diff with default options, and with janestreet profile):

diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml
index 09fca70c1..1da1f0cd0 100644
--- a/infer/src/clang/cTrans.ml
+++ b/infer/src/clang/cTrans.ml
@@ -3374,8 +3374,7 @@ struct
       let is_by_ref =
         (* see http://en.cppreference.com/w/cpp/language/lambda *)
         match lci_capture_kind with
-        | `LCK_ByRef (* explicit with [&x] or implicit with [&] *)
-        | `LCK_This
+        | `LCK_ByRef (* explicit with [&x] or implicit with [&] *) | `LCK_This
         (* explicit with [this] or implicit with [&] *)
         | `LCK_VLAType
         (* capture a variable-length array by reference. we probably don't handle
diff --git a/infer/src/nullsafe/typeOrigin.ml b/infer/src/nullsafe/typeOrigin.ml
index 7099f0713..e2a9a5a45 100644
--- a/infer/src/nullsafe/typeOrigin.ml
+++ b/infer/src/nullsafe/typeOrigin.ml
@@ -56,8 +56,7 @@ let equal = [%compare.equal: t]
 let get_nullability = function
   | NullConst _ -> Nullability.Null
   | NonnullConst _ | This (* `this` can not be null according to Java rules *)
-  | New (* In Java `new` always create a non-null object  *)
-  | ArrayLengthResult
+  | New (* In Java `new` always create a non-null object  *) | ArrayLengthResult
   (* integer hence non-nullable *)
   | InferredNonnull _
   (* WARNING: we trade soundness for usability.
@@ -67,8 +66,7 @@ let get_nullability = function
      We currently don't have a nice way to detect initialization, neither automatical nor manual.
      Hence we make potentially dangerous choice in favor of pragmatism.
   *)
-  | ArrayAccess
-  | OptimisticFallback
+  | ArrayAccess | OptimisticFallback
   (* non-null is the most optimistic type *)
   | Undef
   (* This is a very special case, assigning non-null is a technical trick *) ->
diff --git a/lambda/lambda.ml b/lambda/lambda.ml
index db23401fe..8513e4474 100644
--- a/lambda/lambda.ml
+++ b/lambda/lambda.ml
@@ -440,8 +440,7 @@ let make_key e =
     | Lsend (m, e1, e2, es, _loc) ->
         Lsend (m, tr_rec env e1, tr_rec env e2, tr_recs env es, Location.none)
     | Lifused (id, e) -> Lifused (id, tr_rec env e)
-    | Lletrec _ | Lfunction _ | Lfor _
-    | Lwhile _
+    | Lletrec _ | Lfunction _ | Lfor _ | Lwhile _
     (* Beware: (PR#6412) the event argument to Levent
        may include cyclic structure of type Type.typexpr *)
     | Levent _ ->

which is a fix considering break-cases=fit is used for conventional.

@Julow Julow force-pushed the unstable-cmt-match branch from e2710f3 to e0d69d0 Compare November 28, 2019 13:29
@Julow
Copy link
Collaborator Author

Julow commented Nov 28, 2019

The last two indeed look like a fix. I'm not 100% sure for the first two, I added a test for that.

@gpetiot
Copy link
Collaborator

gpetiot commented Nov 28, 2019

I doubted as well at first because it kinda looks weird since the comment is long, no doubt for a shorter comment. But this is what is expected for break-cases=fit.

@Julow
Copy link
Collaborator Author

Julow commented Nov 28, 2019

I see. I tested too and it's a fix.
Should I put that in the changelog ? If yes, how ?

@gpetiot
Copy link
Collaborator

gpetiot commented Nov 28, 2019

If you don't find this too long I would modify your entry: Fix an unstable comment bug in or-patterns; and fix wrapping of or-patterns in presence of comments when break-cases=fit

@Julow
Copy link
Collaborator Author

Julow commented Nov 28, 2019

That's a bit long for a single line, I tried something.

@gpetiot gpetiot merged commit 4cc12d7 into ocaml-ppx:master Nov 28, 2019
Julow added a commit to Julow/opam-repository that referenced this pull request Jan 28, 2020
CHANGES:

#### New features

  + Add an option `--margin-check` to emit a warning if the formatted output exceeds the margin (ocaml-ppx/ocamlformat#1110) (Guillaume Petiot)
  + Preserve comment indentation when `wrap-comments` is unset (ocaml-ppx/ocamlformat#1138, ocaml-ppx/ocamlformat#1159) (Jules Aguillon)
  + Improve error messages (ocaml-ppx/ocamlformat#1147) (Jules Aguillon)
  + Display standard output in the emacs plugin even when ocamlformat does not fail (ocaml-ppx/ocamlformat#1189) (Guillaume Petiot)

#### Removed

  + Remove `ocamlformat_reason` (ocaml-ppx/ocamlformat#254, ocaml-ppx/ocamlformat#1185) (Etienne Millon).
    This tool has never been released to opam, has no known users, and overlaps
    with what `refmt` can do.
  + Remove `ocamlformat-diff` (ocaml-ppx/ocamlformat#1205) (Guillaume Petiot)
    This tool has never been released to opam, has no known users, and overlaps
    with what `merge-fmt` can do.

#### Packaging

  + Work with base v0.13.0 (ocaml-ppx/ocamlformat#1163) (Jules Aguillon)

#### Bug fixes

  + Fix placement of comments just before a '|' (ocaml-ppx/ocamlformat#1203) (Jules Aguillon)
  + Fix build version detection when building in the absence of a git root (ocaml-ppx/ocamlformat#1198) (Anil Madhavapeddy)
  + Fix wrapping of or-patterns in presence of comments with `break-cases=fit` (ocaml-ppx/ocamlformat#1167) (Jules Aguillon)
    This also fixes an unstable comment bug in or-patterns
  + Fix an unstable comment bug in variant declarations (ocaml-ppx/ocamlformat#1108) (Jules Aguillon)
  + Fix: break multiline comments (ocaml-ppx/ocamlformat#1122) (Guillaume Petiot)
  + Fix: types on named arguments were wrapped incorrectly when preceding comments (ocaml-ppx/ocamlformat#1124) (Guillaume Petiot)
  + Fix the indentation produced by max-indent (ocaml-ppx/ocamlformat#1118) (Guillaume Petiot)
  + Fix break after Psig_include depending on presence of docstring (ocaml-ppx/ocamlformat#1125) (Guillaume Petiot)
  + Remove some calls to if_newline and break_unless_newline and fix break before closing brackets (ocaml-ppx/ocamlformat#1168) (Guillaume Petiot)
  + Fix unstable cmt in or-pattern (ocaml-ppx/ocamlformat#1173) (Guillaume Petiot)
  + Fix location of comment attached to the underscore of an open record (ocaml-ppx/ocamlformat#1208) (Guillaume Petiot)
  + Fix parentheses around optional module parameter (ocaml-ppx/ocamlformat#1212) (Christian Barcenas)
  + Fix grouping of horizontally aligned comments (ocaml-ppx/ocamlformat#1209) (Guillaume Petiot)
  + Fix dropped comments around module pack expressions (ocaml-ppx/ocamlformat#1214) (Jules Aguillon)
  + Fix regression of comment position in list patterns (ocaml-ppx/ocamlformat#1141) (Josh Berdine)
  + Fix: adjust definition of Location.is_single_line to reflect margin (ocaml-ppx/ocamlformat#1102) (Josh Berdine)

#### Documentation

  + Fix documentation of option `version-check` (ocaml-ppx/ocamlformat#1135) (Wilfred Hughes)
  + Fix hint when using `break-separators=after-and-docked` (ocaml-ppx/ocamlformat#1130) (Greta Yorsh)
bogdan2412 pushed a commit to bogdan2412/ocamlformat that referenced this pull request Mar 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: certain match clauses with comments do not stabilize
3 participants