ocaml-ppx / ocamlformat

Auto-formatter for OCaml code
MIT License
622 stars 175 forks source link

Bug: drops comments before begin with exp-grouping=preserve #2543

Open acieroid opened 5 months ago

acieroid commented 5 months ago

Describe the bug OCamlformat drops comments before a begin with exp-grouping=preserve.

How to Reproduce Steps to reproduce the behavior:

Results in:

$ ocamlformat foo.ml
ocamlformat: Cannot process "foo.ml".
  Please report this bug at https://github.com/ocaml-ppx/ocamlformat/issues.
  BUG: comment changed.
File "foo.ml", line 4, characters 4-17:
Error: comment (*  comment  *) dropped.
$ ocamlformat --print-config
comment-check=true
debug=false
disable=false
margin-check=false
max-iters=10
ocaml-version=4.04.0
quiet=false
disable-conf-attrs=false
version-check=true
assignment-operator=end-line (profile default (file .ocamlformat:2))
break-before-in=fit-or-vertical (profile default (file .ocamlformat:2))
break-cases=fit (profile default (file .ocamlformat:2))
break-collection-expressions=fit-or-vertical (profile default (file .ocamlformat:2))
break-colon=after (profile default (file .ocamlformat:2))
break-fun-decl=wrap (profile default (file .ocamlformat:2))
break-fun-sig=wrap (profile default (file .ocamlformat:2))
break-infix=wrap (profile default (file .ocamlformat:2))
break-infix-before-func=false (profile default (file .ocamlformat:2))
break-separators=after (profile default (file .ocamlformat:2))
break-sequences=true (profile default (file .ocamlformat:2))
break-string-literals=auto (profile default (file .ocamlformat:2))
break-struct=force (profile default (file .ocamlformat:2))
cases-exp-indent=4 (profile default (file .ocamlformat:2))
cases-matching-exp-indent=normal (profile default (file .ocamlformat:2))
disambiguate-non-breaking-match=false (profile default (file .ocamlformat:2))
doc-comments=after-when-possible (profile default (file .ocamlformat:2))
doc-comments-padding=2 (profile default (file .ocamlformat:2))
doc-comments-tag-only=default (profile default (file .ocamlformat:2))
dock-collection-brackets=true (profile default (file .ocamlformat:2))
exp-grouping=preserve (file .ocamlformat:3)
extension-indent=2 (profile default (file .ocamlformat:2))
field-space=loose (profile default (file .ocamlformat:2))
function-indent=2 (profile default (file .ocamlformat:2))
function-indent-nested=never (profile default (file .ocamlformat:2))
if-then-else=compact (profile default (file .ocamlformat:2))
indent-after-in=0 (profile default (file .ocamlformat:2))
indicate-multiline-delimiters=no (profile default (file .ocamlformat:2))
indicate-nested-or-patterns=unsafe-no (profile default (file .ocamlformat:2))
infix-precedence=indent (profile default (file .ocamlformat:2))
leading-nested-match-parens=false (profile default (file .ocamlformat:2))
let-and=compact (profile default (file .ocamlformat:2))
let-binding-indent=2 (profile default (file .ocamlformat:2))
let-binding-spacing=compact (profile default (file .ocamlformat:2))
let-module=compact (profile default (file .ocamlformat:2))
line-endings=lf (profile default (file .ocamlformat:2))
margin=80 (profile default (file .ocamlformat:2))
match-indent=0 (profile default (file .ocamlformat:2))
match-indent-nested=never (profile default (file .ocamlformat:2))
max-indent=68 (profile default (file .ocamlformat:2))
module-item-spacing=compact (profile default (file .ocamlformat:2))
nested-match=wrap (profile default (file .ocamlformat:2))
ocp-indent-compat=false (profile default (file .ocamlformat:2))
parens-ite=false (profile default (file .ocamlformat:2))
parens-tuple=always (profile default (file .ocamlformat:2))
parens-tuple-patterns=multi-line-only (profile default (file .ocamlformat:2))
parse-docstrings=false (profile default (file .ocamlformat:2))
parse-toplevel-phrases=false (profile default (file .ocamlformat:2))
sequence-blank-line=preserve-one (profile default (file .ocamlformat:2))
sequence-style=terminator (profile default (file .ocamlformat:2))
single-case=compact (profile default (file .ocamlformat:2))
space-around-arrays=true (profile default (file .ocamlformat:2))
space-around-lists=true (profile default (file .ocamlformat:2))
space-around-records=true (profile default (file .ocamlformat:2))
space-around-variants=true (profile default (file .ocamlformat:2))
stritem-extension-indent=0 (profile default (file .ocamlformat:2))
type-decl=compact (profile default (file .ocamlformat:2))
type-decl-indent=2 (profile default (file .ocamlformat:2))
wrap-comments=false (profile default (file .ocamlformat:2))
wrap-fun-args=true (profile default (file .ocamlformat:2))
profile=default (file .ocamlformat:2)
$ ocaml --version
The OCaml toplevel, version 4.14.1
Julow commented 5 months ago

Thanks for reporting! This is fixed on main. It seems to be the same as https://github.com/ocaml-ppx/ocamlformat/issues/2539