From 268a36b549694a1b518a00fefb5513b5cc1c96dd Mon Sep 17 00:00:00 2001 From: dawe Date: Thu, 6 Jun 2024 16:00:11 +0200 Subject: [PATCH] - guard against a newline induced precedence change to fix 2866 - add test - add changelog entry --- CHANGELOG.md | 4 ++-- .../PatternMatchingTests.fs | 23 +++++++++++++++++++ src/Fantomas.Core/CodePrinter.fs | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8a5d3fa57..b47d80445b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Fantomas.Core.Tests/PatternMatchingTests.fs b/src/Fantomas.Core.Tests/PatternMatchingTests.fs index 74db05a604..6b4bb86383 100644 --- a/src/Fantomas.Core.Tests/PatternMatchingTests.fs +++ b/src/Fantomas.Core.Tests/PatternMatchingTests.fs @@ -2286,3 +2286,26 @@ match synExpr with ) -> Some ident.idRange | _ -> defaultTraverse synExpr """ + +[] +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 +""" diff --git a/src/Fantomas.Core/CodePrinter.fs b/src/Fantomas.Core/CodePrinter.fs index de5cba95e8..5a13896a61 100644 --- a/src/Fantomas.Core/CodePrinter.fs +++ b/src/Fantomas.Core/CodePrinter.fs @@ -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 =