diff --git a/src/Fantomas.Tests/LetBindingTests.fs b/src/Fantomas.Tests/LetBindingTests.fs index 5ce31a030d..22f3947efb 100644 --- a/src/Fantomas.Tests/LetBindingTests.fs +++ b/src/Fantomas.Tests/LetBindingTests.fs @@ -1877,3 +1877,98 @@ let a = x in foo x """ let a = x in foo x """ + +[] +let ``let binding as part of sequential inside parenthesis, 1805`` () = + formatSourceString + false + """ +module Foo = + let foo = + lazy ( + if not <| bar then + raise <| Exception "Very very very very very very very very very very very very very very long" + let ret = false + if ret then + "foo" + else + "bar" + |> log.Info + ret + ) +""" + config + |> prepend newline + |> should + equal + """ +module Foo = + let foo = + lazy + (if not <| bar then + raise + <| Exception "Very very very very very very very very very very very very very very long" + + let ret = false + + if ret then "foo" else "bar" + |> log.Info + + ret) +""" + +[] +let ``sequential inside parenthesis, 1777`` () = + formatSourceString + false + """ +if kind = shiftFlag then ( + if errorSuppressionCountDown > 0 then + errorSuppressionCountDown <- errorSuppressionCountDown - 1 +#if DEBUG + if Flags.debug then Console.WriteLine("shifting, reduced errorRecoveryLevel to {0}\n", errorSuppressionCountDown) +#endif + let nextState = actionValue action + if not haveLookahead then failwith "shift on end of input!" + let data = tables.dataOfToken lookaheadToken + valueStack.Push(ValueInfo(data, lookaheadStartPos, lookaheadEndPos)) + stateStack.Push(nextState) +#if DEBUG + if Flags.debug then Console.WriteLine("shift/consume input {0}, shift to state {1}", report haveLookahead lookaheadToken, nextState) +#endif + haveLookahead <- false + + ) +""" + config + |> prepend newline + |> should + equal + """ +if kind = shiftFlag then + (if errorSuppressionCountDown > 0 then + errorSuppressionCountDown <- errorSuppressionCountDown - 1 +#if DEBUG + if Flags.debug then + Console.WriteLine("shifting, reduced errorRecoveryLevel to {0}\n", errorSuppressionCountDown) +#endif + let nextState = actionValue action + + if not haveLookahead then + failwith "shift on end of input!" + + let data = tables.dataOfToken lookaheadToken + valueStack.Push(ValueInfo(data, lookaheadStartPos, lookaheadEndPos)) + stateStack.Push(nextState) +#if DEBUG + if Flags.debug then + Console.WriteLine( + "shift/consume input {0}, shift to state {1}", + report haveLookahead lookaheadToken, + nextState + ) +#endif + haveLookahead <- false + + ) +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index c6170952a1..27d56ff9b4 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -1610,7 +1610,8 @@ and genExpr astContext synExpr ctx = ctx | Paren (lpr, e, rpr, pr) -> match e with - | LetOrUses _ -> + | LetOrUses _ + | Sequential (_, LetOrUses _, _) -> sepOpenTFor lpr +> atCurrentColumn (genExpr astContext e) +> sepCloseTFor rpr pr