ocamlformat icon indicating copy to clipboard operation
ocamlformat copied to clipboard

Bug: comments on record fields reordered

Open bcc32 opened this issue 3 years ago • 2 comments

Describe the bug Some comments in record fields are misplaced and reordered relative to each other.

How to Reproduce

Given the input file:

type t =
  { a : int
  ; (* first comment for float fields *)
    (* second comment for float fields *)

    (* comment about b *)
    b : float
  ; (* comment about c *)
    c : float
  }

Formatting this file in 0.19.0 gives:

type t =
  { a : int (* second comment for float fields *)
  ; (* first comment for float fields *)

    (* comment about b *)
    b : float
  ; (* comment about c *)
    c : float
  }

The second comment for float fields comment has moved before the semicolon separating fields, and also now comes before first comment for float fields.

Options:

--enable-outside-detected-project
--profile=janestreet
--disable-conf-files

bcc32 avatar Aug 03 '21 15:08 bcc32

FYI, this doesn't appear to happen with semicolon separated lists:

let x =
  [ a
  ; (* first comment *)
    (* second comment *)

    (* comment about b *)
    b
  ; (* comment about c *)
    c
  ]

is formatted as-is.

bcc32 avatar Aug 03 '21 15:08 bcc32

I had a look at this one, the issue is that the "easy fix" that would fix this one would introduce regressions in a lot of places because the comment placement code is very fragile. I am still working my way up to improving the comments situation by improving the ast.

gpetiot avatar Aug 24 '21 09:08 gpetiot