Skip to content

Inline transformations do not remove odoc comments #568

@jaymody

Description

@jaymody

The following:

[@@@expand_inline
(** i am bar *)
let bar = 10
]
(** i am foo *)
let foo = 10
[@@@end] 

Would get corrected to:

[@@@expand_inline
(** i am bar *)
let bar = 10
]
(** i am foo *)
let bar = 10 [@@ocaml.doc {| i am bar |}]
[@@@end] 

The problem is that the location of structure/signature items do not include the location of attached odoc comments via (** *). Consequently, when ppxlib is deciding which part of the source code to overwrite in a correction file, this ends up not including odoc comments. Note, this is not a bug with [@@@expand_inline] specifically, but for any transformation that registers a correction file (however, this would be extremely unlikely to occur with [@@deriving_inline] unless the user was doing some really funky stuff). A more likely scenario for how one might encounter this bug:

  1. You wrap some existing code inside an [@@@expand_inline] block.
  2. You copy that same code into the payload of [@@@expand_inline].
  3. You accept the correction and you get something like the above.

Arguably, this is a parser bug. Structure and signature items should include the locations of any attached odoc comments. That being said, this bug is really rare to come across and not urgent to fix imo. I thought I'd just make an issue here to document it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions