diff --git a/src/Fantomas.Tests/ControlStructureTests.fs b/src/Fantomas.Tests/ControlStructureTests.fs index bd97430406..61e43d29d7 100644 --- a/src/Fantomas.Tests/ControlStructureTests.fs +++ b/src/Fantomas.Tests/ControlStructureTests.fs @@ -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 + () +""" + +[] +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 () diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index e879ca1c6c..695825adc6 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -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