Skip to content

Commit

Permalink
Don't add extra parenthesis for SynType.Fun. Fixes fsprojects#1057.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Sep 2, 2020
1 parent cd4cefc commit 64da217
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/Fantomas.Tests/SignatureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -722,4 +722,36 @@ module Some_module
type foo = bool
val bar: bool
"""

[<Test>]
let ``don't add duplicate parentheses for TypeAbbrev, 1057`` () =
formatSourceString false """
type AB = A -> B list * C -> D
type AB = A -> (B list * C -> D)
type AB = A -> ((B list * C -> D))
type AB = A -> (C -> D)
""" config
|> prepend newline
|> should equal """
type AB = A -> B list * C -> D
type AB = A -> (B list * C -> D)
type AB = A -> ((B list * C -> D))
type AB = A -> (C -> D)
"""

[<Test>]
let ``don't add duplicate parentheses for TypeAbbrev in signature file`` () =
formatSourceString true """
namespace Foo
type AB = A -> (B list * C -> D)
""" config
|> prepend newline
|> should equal """
namespace Foo
type AB = A -> (B list * C -> D)
"""
2 changes: 1 addition & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2827,7 +2827,7 @@ and genType astContext outerBracket t =
| TAnon -> sepWild
| TVar tp -> genTypar astContext tp
// Drop bracket around tuples before an arrow
| TFun(TTuple ts, t) -> sepOpenT +> loopTTupleList ts +> sepArrow +> loop t +> sepCloseT
| TFun(TTuple ts, t) -> loopTTupleList ts +> sepArrow +> loop t
// Do similar for tuples after an arrow
| TFun(t, TTuple ts) -> sepOpenT +> loop t +> sepArrow +> loopTTupleList ts +> sepCloseT
| TFuns ts -> col sepArrow ts loop
Expand Down

0 comments on commit 64da217

Please sign in to comment.