Skip to content

Apply stroustrup bracket style to object expressions - #3450

Merged
nojaf merged 2 commits into
fsprojects:mainfrom
nojaf:obj-expr-stroustrup
Aug 29, 2026
Merged

Apply stroustrup bracket style to object expressions#3450
nojaf merged 2 commits into
fsprojects:mainfrom
nojaf:obj-expr-stroustrup

Conversation

@nojaf

@nojaf nojaf commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Object expressions were printed by the aligned branch whatever MultilineBracketStyle said, so { new T with stayed on one line and stroustrup was the only bracket style that did not reach every bracket it names. They now have a branch of their own, and Expr.ObjExpr counts as a stroustrup-style expression, so the brace stays on the line that opens the binding and new T with moves below it. This is the form the Microsoft style guide writes out under "Formatting object expressions". It was left alone in the belief that the layout produced an offside error, which no compiler back to F# 6 agrees with.

Two places that were overriding stroustrup are lifted along with it, for every bracket kind rather than for object expressions alone. A match clause governed by ExperimentalKeepIndentInBranch no longer takes the decision away from a stroustrup body, and a binding whose signature broke across lines now gets the stroustrup body layout that the single-line path already had.

The closing bracket of a stroustrup body in a match clause stays two columns right of the bar. On the bar's own column the | of the next clause no longer parses, and giving only the last clause the bar's column would leave two columns in one match; a comment records both.

Fixes #2990

nojaf added 2 commits August 29, 2026 11:02
Object expressions were printed by the aligned branch whatever
MultilineBracketStyle said, so `{ new T with` stayed on one line and
stroustrup was the only bracket style that did not reach every bracket it
names. They now have a branch of their own, and Expr.ObjExpr counts as a
stroustrup-style expression, so the brace stays on the line that opens the
binding and `new T with` moves below it. This is the form the Microsoft
style guide writes out under "Formatting object expressions". It was left
alone in the belief that the layout produced an offside error, which no
compiler back to F# 6 agrees with.

Two places that were overriding stroustrup are lifted along with it, for
every bracket kind rather than for object expressions alone. A match clause
governed by ExperimentalKeepIndentInBranch no longer takes the decision away
from a stroustrup body, and a binding whose signature broke across lines now
gets the stroustrup body layout that the single-line path already had.

The closing bracket of a stroustrup body in a match clause stays two columns
right of the bar. On the bar's own column the `|` of the next clause no
longer parses, and giving only the last clause the bar's column would leave
two columns in one match; a comment records both.
@nojaf
nojaf merged commit fc79c69 into fsprojects:main Aug 29, 2026
6 checks passed
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.

Newline inconsistency in object expression

1 participant