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

Bug: infix operator dropped #2406

Closed
hhugo opened this issue Jul 21, 2023 · 3 comments · Fixed by #2445
Closed

Bug: infix operator dropped #2406

hhugo opened this issue Jul 21, 2023 · 3 comments · Fixed by #2445

Comments

@hhugo
Copy link
Collaborator

hhugo commented Jul 21, 2023

when using ocp-indent-compat = true
I see the following invalid rewriting.

taken from ocsigen-start.6.1.0:tools/sort_deps.ml

let add_edge target dep =
  if target <> dep
  then (
    Hashtbl.replace edges dep
-      (target :: (try Hashtbl.find edges dep with Not_found -> []));
+      (target (try Hashtbl.find edges dep with Not_found -> []));
    Hashtbl.replace edge_count target
-      (1 + try Hashtbl.find edge_count target with Not_found -> 0);
+      (1 try Hashtbl.find edge_count target with Not_found -> 0);
    if not (Hashtbl.mem edge_count dep) then Hashtbl.add edge_count dep 0)
@hhugo hhugo mentioned this issue Jul 21, 2023
20 tasks
@gpetiot
Copy link
Collaborator

gpetiot commented Sep 13, 2023

I couldn't fix it but the issue is located in https://github.com/ocaml-ppx/ocamlformat/blob/main/lib/Fmt_ast.ml#L1615-L1623

The way the breaks are added is very flimsy

@hhugo
Copy link
Collaborator Author

hhugo commented Sep 18, 2023

The following diff seems to fix the issue.

diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml
index 36d43f5d..d544d3de 100644
--- a/lib/Fmt_ast.ml
+++ b/lib/Fmt_ast.ml
@@ -2361,6 +2361,7 @@ and fmt_expression c ?(box = true) ?pro ?epi ?eol ?parens ?(indent_wrap = 0)
         if c.conf.fmt_opts.leading_nested_match_parens.v then (false, None)
         else (parenze_exp xpc_rhs, Some false)
       in
+      fmt_opt epi $
       Params.Exp.wrap c.conf ~parens ~disambiguate:true
         (hvbox 2
            ( hvbox 0

@Julow
Copy link
Collaborator

Julow commented Sep 18, 2023

Indeed. I went into the rabbit hole of fixing ~pro, ~epi and ~box in fmt_expression in every cases but never got out: https://github.com/Julow/ocamlformat/tree/ocp-indent-op-removed

We might want to use ~pro instead of ~epi and remove the later, as its use doesn't correspond to its name and is used in very few cases.

Julow added a commit to Julow/ocamlformat that referenced this issue Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants