Skip to content

Commit

Permalink
Merge pull request #3094 from dawedawe/fix_2866
Browse files Browse the repository at this point in the history
Guard against a newline induced precedence change
  • Loading branch information
dawedawe authored Jun 6, 2024
2 parents 7676a03 + 268a36b commit 854d9b3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
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

0 comments on commit 854d9b3

Please sign in to comment.