Skip to content

Commit

Permalink
- add missing construction of return info node for deconstructed tupl…
Browse files Browse the repository at this point in the history
…es to fix 2942

- add test cases
- add CHANGELOG entry
  • Loading branch information
dawedawe committed Jun 2, 2024
1 parent 753676d commit 26a37fa
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 26a37fa

Please sign in to comment.