Skip to content

Keep the } of a Stroustrup record copy and the ) of a call at their indent after a comment - #3565

Merged
nojaf merged 1 commit into
fsprojects:v9.0from
nojaf:fix-3564
Oct 30, 2026
Merged

nojaf merged 1 commit into
fsprojects:v9.0from
nojaf:fix-3564

Conversation

@nojaf

@nojaf nojaf commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

A comment at the end of a bracketed block, after the last field of a record copy or after the argument of a call, left the closing bracket one indent too deep: at the comment's column, instead of where it goes when there is no comment. The result compiled, so only the layout was wrong. 8.1.0 has the same bug, as #3564 shows.

Fixes #3564

What changes for you

The - lines are v9.0 at 940bae9, the + lines this pull request at 6fcd929.

A record copy in Stroustrup style

[*.{fs,fsi}]
fsharp_multiline_bracket_style = stroustrup
let updated =
    { someRecordValue with
        FieldNumberOne = 1
        FieldNumberTwo = 2
        // trailing comment
    }
 let updated = {
     someRecordValue with
         FieldNumberOne = 1
         FieldNumberTwo = 2
         // trailing comment
-    }
+}

An anonymous record copy, {| someRecordValue with ... |}, changes the same way.

A call whose argument has a comment before and after it

let app =
    builder.UseUrls(
        // the public endpoint
        url
        // the end of the arguments
    )
 let app =
     builder.UseUrls(
         // the public endpoint
         url
         // the end of the arguments
-        )
+    )

A call with only the comment after its argument already kept ) at the column of the call, and still does.

A comment after the last field of a Stroustrup record copy left the
closing brace one indent too deep, and a comment after the argument of a
call, with another one before it, left the closing parenthesis under the
argument.

Both closed with a plain unindent followed by
sepNlnUnlessLastEventIsNewline. That reuses the newline the comment
wrote, and a newline is indented when it is written: the unindent after
it never reached the line, so the bracket stayed at the indent from
before. unindentWithTriviaAwareness moves the comment's newline past its
UnIndentBy, so the line after the comment starts at the unindented
column.

Fixes fsprojects#3564
@nojaf
nojaf changed the base branch from main to v9.0 October 30, 2026 14:49
@nojaf nojaf changed the title Check that formatted output keeps every comment Keep a closing bracket at its indent after a trailing comment Oct 30, 2026
@nojaf nojaf changed the title Keep a closing bracket at its indent after a trailing comment Keep the } of a Stroustrup record copy and the ) of a call at their indent after a comment Oct 30, 2026
@nojaf
nojaf merged commit c5b532a into fsprojects:v9.0 Oct 30, 2026
40 checks passed
@nojaf
nojaf deleted the fix-3564 branch October 30, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant