Skip to content

Commit

Permalink
Wrap boolean condition in parenthesis if try/catch/finally. Fixes fsp…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Aug 21, 2020
1 parent 8665356 commit f19c3b9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
29 changes: 26 additions & 3 deletions src/Fantomas.Tests/ControlStructureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,32 @@ let x =
|> prepend newline
|> should equal """
let x =
if try
true
with Failure _ -> false then
if (try
true
with Failure _ -> false) then
()
else
()
"""

[<Test>]
let ``try finally in if expression`` () =
formatSourceString false """
let y =
if try true
finally false
then
()
else
()
""" config
|> prepend newline
|> should equal """
let y =
if (try
true
finally
false) then
()
else
()
Expand Down
5 changes: 4 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,10 @@ and genExpr astContext synExpr =
// x
// bool expr x should be indented
+> ifElse hasCommentAfterIfKeyword (indent +> sepNln) sepNone
+> genExpr astContext e1
+> (match e1 with
| SynExpr.TryWith _
| SynExpr.TryFinally _ -> sepOpenT +> genExpr astContext e1 +> sepCloseT
| _ -> genExpr astContext e1)
+> ifElse hasCommentAfterBoolExpr sepNln sepSpace
+> genThen synExpr.Range
// f.ex if x then // meh
Expand Down

0 comments on commit f19c3b9

Please sign in to comment.