Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard against a newline induced precedence change #3094

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Changelog

## [Unreleased]
## 6.3.8 - 2024-06-06

### Fixed
* Fix loss of tuple type annotation without parens. [#2942](https://github.com/fsprojects/fantomas/issues/2942)
* Fix precedence change of `||>` due to inserted newline. [#2866](https://github.com/fsprojects/fantomas/issues/2866)

## 6.3.7 - 2024-06-01

Expand Down
23 changes: 23 additions & 0 deletions src/Fantomas.Core.Tests/PatternMatchingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2286,3 +2286,26 @@ match synExpr with
) -> Some ident.idRange
| _ -> defaultTraverse synExpr
"""

[<Test>]
let ``insertion of a newline changes precedence of the ||> operator, 2866`` () =
formatSourceString
"""
let value =
match "string" with
| "value" -> "1", "2"
| _ -> "111111111111111111111111111111111111111111111111111111111111111111111", "22222222222222222222222222222222222"
||> createTuple
"""
config
|> prepend newline
|> should
equal
"""
let value =
(match "string" with
| "value" -> "1", "2"
| _ ->
"111111111111111111111111111111111111111111111111111111111111111111111", "22222222222222222222222222222222222")
||> createTuple
"""
2 changes: 1 addition & 1 deletion src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2163,7 +2163,7 @@ let genMultilineInfixExpr (node: ExprInfixAppNode) =
match node.LeftHandSide with
| IsIfThenElse _ when (ctx.Config.IndentSize - 1 <= node.Operator.Text.Length) ->
autoParenthesisIfExpressionExceedsPageWidth (genExpr node.LeftHandSide) ctx
| Expr.Match _ when (ctx.Config.IndentSize <= node.Operator.Text.Length) ->
| Expr.Match _ when (ctx.Config.IndentSize - 1 <= node.Operator.Text.Length) ->
let ctxAfterMatch = genExpr node.LeftHandSide ctx

let lastClauseIsSingleLine =
Expand Down
Loading