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: Incorrect indentation of records with trailing comments #2565

Open
NoahTheDuke opened this issue Jul 26, 2024 · 1 comment
Open

Bug: Incorrect indentation of records with trailing comments #2565

NoahTheDuke opened this issue Jul 26, 2024 · 1 comment

Comments

@NoahTheDuke
Copy link

Describe the bug

When constructing a record, if there are comments at the end of a given line but the length of the whole record isn't beyond margin, then the indentation will be very weird.

type very_long_type = { first : int; second : int; third : int }

let create () : very_long_type =
  { first = 1; (* first *)
    second = 1; (* second *)
    third = 1 (* third *) }

If you manually join the lines together, then you get a 75 characters long line (under the margin of 80 characters):

let create () : very_long_type =
  { first = 1; (* first *) second = 1; (* second *) third = 1 (* third *) }

However, formatting the file from the first or second example produces:

let create () : very_long_type =
  { first = 1; (* first *)
               second = 1; (* second *)
                           third = 1 (* third *) }

Compare this to when a comment is long enough to push it past the margin:

let create () : very_long_type =
  {
    first = 1;
    (* a very very very very very long comment *)
    second = 1;
    (* second *)
    third = 1 (* third *);
  }

Expected result

Either put it all on one line or split it up like it's too long.

How to Reproduce

Steps to reproduce the behavior:

  • Open a new ocaml file, add the first snippet to it, run ocamlformat over it.

Config

Results from ocamlformat --print-config
$ 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
break-before-in=fit-or-vertical
break-cases=fit
break-collection-expressions=fit-or-vertical
break-colon=after
break-fun-decl=wrap
break-fun-sig=wrap
break-infix=wrap
break-infix-before-func=false
break-separators=after
break-sequences=true
break-string-literals=auto
break-struct=force
cases-exp-indent=4
cases-matching-exp-indent=normal
disambiguate-non-breaking-match=false
doc-comments=after-when-possible
doc-comments-padding=2
doc-comments-tag-only=default
dock-collection-brackets=true
exp-grouping=parens
extension-indent=2
field-space=loose
function-indent=2
function-indent-nested=never
if-then-else=compact
indent-after-in=0
indicate-multiline-delimiters=no
indicate-nested-or-patterns=unsafe-no
infix-precedence=indent
leading-nested-match-parens=false
let-and=compact
let-binding-indent=2
let-binding-spacing=compact
let-module=compact
line-endings=lf
margin=80
match-indent=0
match-indent-nested=never
max-indent=68
module-item-spacing=compact
nested-match=wrap
ocp-indent-compat=false
parens-ite=false
parens-tuple=always
parens-tuple-patterns=multi-line-only
parse-docstrings=false
parse-toplevel-phrases=false
sequence-blank-line=preserve-one
sequence-style=terminator
single-case=compact
space-around-arrays=true
space-around-lists=true
space-around-records=true
space-around-variants=true
stritem-extension-indent=0
type-decl=compact
type-decl-indent=2
wrap-comments=false
wrap-fun-args=true
profile=default
@NoahTheDuke
Copy link
Author

I don't know if this is covered by #2371, I'm running 0.26.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant