Skip to content

Comment before a let in the right-hand side of an infix operator is lost #3522

Closed

Description

@nojaf

Issue created from fantomas-online

Code

a &&
// c
let c = b
c

Formatted code

a
&& let c = b in c

Reformatted code

a && let c = b in c

Problem description

A comment on its own line before a let (also use, let!) in the right-hand side of an infix operator is removed, when Fantomas adds in to the binding (#1461).

Matters not: the operator (&&, ||, +), line or block comment, first or later binding, top level or inside a let. Default settings.

The comment is kept when there is no binding after the operator (if, match, an application), when it is after the last binding, or when it is on the operator's line (&& // c).

Regression: 6.3.16 and 7.0.6 keep it, 8.0.0-alpha-001 to 8.0.7 drop it. Probable cause: genExprInMultilineInfixExpr (CodePrinter.fs) builds a new BindingNode and ExprCompExprBodyNode to add in, without the trivia of the originals. 7.x printed the original nodes with genNode.

Also, a && let c = b in c without a comment is not idempotent on main.

Found in IsSigExactMatch in the F# compiler's MethodOverrides.fs, which loses 19 comment lines. Maybe related: #1512.

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 5 commits that reference this issue on Oct 14, 2026
    7fb7145
    79d0786
    67e8113
    72436c3
    1ab2397
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