From 26a37fa2afef563ae3572193cd06d89699198d9e Mon Sep 17 00:00:00 2001 From: dawe Date: Sun, 2 Jun 2024 23:45:49 +0200 Subject: [PATCH] - add missing construction of return info node for deconstructed tuples to fix 2942 - add test cases - add CHANGELOG entry --- CHANGELOG.md | 5 ++++ src/Fantomas.Core.Tests/TupleTests.fs | 36 +++++++++++++++++++++++++++ src/Fantomas.Core/CodePrinter.fs | 6 +++++ 3 files changed, 47 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4895deda64..f8a5d3fa57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [Unreleased] + +### Fixed +* Fix loss of tuple type annotation without parens. [#2942](https://github.com/fsprojects/fantomas/issues/2942) + ## 6.3.7 - 2024-06-01 ### Fixed diff --git a/src/Fantomas.Core.Tests/TupleTests.fs b/src/Fantomas.Core.Tests/TupleTests.fs index 55aa349a34..a5c7d11ce3 100644 --- a/src/Fantomas.Core.Tests/TupleTests.fs +++ b/src/Fantomas.Core.Tests/TupleTests.fs @@ -515,3 +515,39 @@ a |> fun b -> if b then 0 else 1 """ a |> (fun b -> if b then 0 else 1), 2 """ + +[] +let ``removes type annotation without parens, 2942`` () = + formatSourceString + """ +let clReducedValues, clFirstActualKeys, clSecondActualKeys: ClArray<'a> * ClArray * ClArray = + reduce processor DeviceOnly resultLength clOffsets clFirstKeys clSecondKeys clValues +""" + config + |> prepend newline + |> should + equal + """ +let clReducedValues, clFirstActualKeys, clSecondActualKeys: ClArray<'a> * ClArray * ClArray = + reduce processor DeviceOnly resultLength clOffsets clFirstKeys clSecondKeys clValues +""" + +[] +let ``removes type annotation without parens multiline, 2942`` () = + formatSourceString + """ +let clReducedValues, // some comment 1 + clFirstActualKeys, // some comment 2 + clSecondActualKeys: ClArray<'a> * ClArray * ClArray = + reduce processor DeviceOnly resultLength clOffsets clFirstKeys clSecondKeys clValues +""" + config + |> prepend newline + |> should + equal + """ +let (clReducedValues, // some comment 1 + clFirstActualKeys, // some comment 2 + clSecondActualKeys): ClArray<'a> * ClArray * ClArray = + reduce processor DeviceOnly resultLength clOffsets clFirstKeys clSecondKeys clValues +""" diff --git a/src/Fantomas.Core/CodePrinter.fs b/src/Fantomas.Core/CodePrinter.fs index 4694bec31f..de5cba95e8 100644 --- a/src/Fantomas.Core/CodePrinter.fs +++ b/src/Fantomas.Core/CodePrinter.fs @@ -2986,6 +2986,12 @@ let genBinding (b: BindingNode) (ctx: Context) : Context = let genDestructedTuples = expressionFitsOnRestOfLine (genPat pat) (sepOpenT +> genPat pat +> sepCloseT) + +> optSingle + (fun (rt: BindingReturnInfoNode) -> + genSingleTextNode rt.Colon + +> sepSpace + +> atCurrentColumnIndent (genType rt.Type)) + b.ReturnType genXml b.XmlDoc +> genAttrAndPref