Bug: infix operator splitting fails with anonymous functions
Describe the bug
break-infix = fit-or-vertical not respected when the expression after the infix operator is a fun or a function. Expected behaviour of this option:
let () =
aaaaaaaaaaaaaaaaaaaaaaaaaaaa
|> bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|> cccccc
|> ddddddddd
but for anonymous functions, the infix operators are not broken onto separate lines:
let () =
aaaaaaaaaaaaaaaaaaaaaaaaaaaa |> bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |> cccccc
|> fun x -> ddddddddddd
let () =
aaaaaaaaaaaaaaaaaaaaaaaaaaaa |> bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |> cccccc
|> function
| x -> ddddddddddd
How to Reproduce
break-infix = fit-or-vertical
I'm looking at it but the interaction with break-infix-before-func=false (which is set to false by the conventional profile) is unclear:
for break-infix-before-func=false and break-infix=fit-or-vertical, do we want:
let _ =
aaaaaaaaaaaaaaaa
|> bbbbbbbbbbbbbbbb
|> ccccccccccccccccc
|> fun x -> ddddddddddddddd
or
let _ =
aaaaaaaaaaaaaaaa
|> bbbbbbbbbbbbbbbb
|> ccccccccccccccccc |> fun x ->
ddddddddddddddd
the last one being the closer to the expected behavior of break-infix-before-func=false:
let _ =
aaaaaaaaaaaa >>= fun x ->
bbbbbbbbbbbbbbbb >|= fun y ->
ccccccccccccccccc
I think the second one respects the intent of break-infix-before-func (which I didn't know about), so I recommend that :slightly_smiling_face:
Personally, I'd rather have the first one for consistency (so looks like I'm going to be setting break-infix-before-func=true from now on.
This gets formatted as:
let () =
aaaaaaaaaaaaaaaaaaaaaaaaaaaa
|> bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|> cccccc
|> fun x -> ddddddddddd
let () =
aaaaaaaaaaaaaaaaaaaaaaaaaaaa
|> bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|> cccccc
|> function x -> ddddddddddd
shall we close this issue or did you witness it since then?
Hmm, I don't observe the formatting that you describe.
Here's a branch that adds a test case containing my examples above, and I believe it demonstrates that the issue still exists: https://github.com/CraigFe/ocamlformat/tree/repro-issue-1094
Ah yes my bad, my config was applying profile=ocamlformat which sets --break-infix-before-func