Skip to content

Comment after a property accessor is lost #3527

Closed

Description

@nojaf

Issue created from fantomas-online

Code

type T() =
    member _.X
        with get () = 1 // get
        and set (_: int) = ()

Result

type T() =
    member _.X
        with get () = 1
        and set (_: int) = ()

Problem description

A comment after the body of a property accessor is removed. The output is valid F#, but the comment is gone.

It needs only the default settings. The same happens:

  • after the setter (and set (_: int) = () // set),
  • with a block comment ((* get *)) instead of a line comment,
  • with a setter alone (member _.X with set (_: int) = () // set).

The comment is kept:

  • with a getter alone, which becomes member _.X = 1 // get,
  • when the comment is on its own line above with.

It is not a regression: 8.0.7, 7.0.6, 6.3.16 and 5.2.4 drop the comment too, and so does main.

Trivia assignment puts the comment after the PropertyGetSetBindingNode of the accessor, but genProperty in the MemberDefn.PropertyGetSet case of CodePrinter.fs prints that node without genNode, so its trivia is never written. #1009 was about comments on members with get/set too.

Found while testing the comment search of #1353, which refuses this output.

Extra information

  • The formatted result breaks my code.
  • The formatted result gives compiler warnings.
  • I or my company would be willing to help fix this.
  • I would like a release if this problem is solved.

Options

Fantomas main branch at 2026-10-06T23:08:00Z - 6276e9e

Default Fantomas configuration

Did you know that you can ignore files when formatting by using a .fantomasignore file?
PS: It's unlikely that someone else will solve your specific issue, as it's something that you have a personal stake in.

Activity

  1. added a commit that references this issue on Oct 16, 2026
    1d3f1f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions