Skip to content

Commit

Permalink
Merge pull request #3093 from dawedawe/fix_2942
Browse files Browse the repository at this point in the history
add missing construction of return info node for deconstructed tuples
  • Loading branch information
dawedawe authored Jun 3, 2024
2 parents 753676d + 26a37fa commit 7676a03
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
36 changes: 36 additions & 0 deletions src/Fantomas.Core.Tests/TupleTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,39 @@ a |> fun b -> if b then 0 else 1
"""
a |> (fun b -> if b then 0 else 1), 2
"""

[<Test>]
let ``removes type annotation without parens, 2942`` () =
formatSourceString
"""
let clReducedValues, clFirstActualKeys, clSecondActualKeys: ClArray<'a> * ClArray<int> * ClArray<int> =
reduce processor DeviceOnly resultLength clOffsets clFirstKeys clSecondKeys clValues
"""
config
|> prepend newline
|> should
equal
"""
let clReducedValues, clFirstActualKeys, clSecondActualKeys: ClArray<'a> * ClArray<int> * ClArray<int> =
reduce processor DeviceOnly resultLength clOffsets clFirstKeys clSecondKeys clValues
"""

[<Test>]
let ``removes type annotation without parens multiline, 2942`` () =
formatSourceString
"""
let clReducedValues, // some comment 1
clFirstActualKeys, // some comment 2
clSecondActualKeys: ClArray<'a> * ClArray<int> * ClArray<int> =
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<int> * ClArray<int> =
reduce processor DeviceOnly resultLength clOffsets clFirstKeys clSecondKeys clValues
"""
6 changes: 6 additions & 0 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7676a03

Please sign in to comment.