From 64da217d1f025213733e35d398ff27fa76e0f0c6 Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 2 Sep 2020 17:15:09 +0200 Subject: [PATCH] Don't add extra parenthesis for SynType.Fun. Fixes #1057. --- src/Fantomas.Tests/SignatureTests.fs | 32 ++++++++++++++++++++++++++++ src/Fantomas/CodePrinter.fs | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Fantomas.Tests/SignatureTests.fs b/src/Fantomas.Tests/SignatureTests.fs index b4fa18ee72..aa0d840e3d 100644 --- a/src/Fantomas.Tests/SignatureTests.fs +++ b/src/Fantomas.Tests/SignatureTests.fs @@ -722,4 +722,36 @@ module Some_module type foo = bool val bar: bool +""" + +[] +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) +""" + +[] +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) """ \ No newline at end of file diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 01f3a3bb8b..33868ce9f5 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -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