diff --git a/src/Fantomas.Tests/ComputationExpressionTests.fs b/src/Fantomas.Tests/ComputationExpressionTests.fs index 8025bc6160..238edcd863 100644 --- a/src/Fantomas.Tests/ComputationExpressionTests.fs +++ b/src/Fantomas.Tests/ComputationExpressionTests.fs @@ -180,3 +180,50 @@ observable { and! b = bar return a + b } """ + +[] +let ``let bang should be formatted as regular let, 615`` () = + formatSourceString false """ +let f = + async { + // Without binding newline after assignment sign preserved, which is expected behavior + let r = + match 0 with + | _ -> () + + return r + } + +let f2 = + async { + // When binding, newline force-removed, which makes the whole expression + // on the right side to be indented. + let! r = match 0 with + | _ -> () |> async.Return + + return r + } +""" config + |> prepend newline + |> should equal """ +let f = + async { + // Without binding newline after assignment sign preserved, which is expected behavior + let r = + match 0 with + | _ -> () + + return r + } + +let f2 = + async { + // When binding, newline force-removed, which makes the whole expression + // on the right side to be indented. + let! r = + match 0 with + | _ -> () |> async.Return + + return r + } +""" \ No newline at end of file diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 93c19c2118..3575fee918 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -1439,17 +1439,16 @@ and genExpr astContext synExpr = addParenIfAutoNln e1 (genExpr astContext) -- sprintf " <- " +> genExpr astContext e2 | LetOrUseBang(isUse, p, e1, ands, e2) -> - let genAndList astContext (ands: list) = colPost sepNln sepNln ands (fun (_,_,_,pat,expr,_) -> !- "and! " +> genPat astContext pat -- " = " +> genExpr astContext expr) - atCurrentColumn (ifElse isUse (!- "use! ") (!- "let! ") - +> genPat astContext p -- " = " +> genExpr astContext e1 +> sepNln - +> genAndList astContext ands - +> genExpr astContext e2 - ) + ifElse isUse (!- "use! ") (!- "let! ") +> genPat astContext p -- " = " + +> autoIndentNlnByFuture (genExpr astContext e1) + +> sepNln + +> genAndList astContext ands + +> genExpr astContext e2 | ParsingError r -> raise <| FormatException (sprintf "Parsing error(s) between line %i column %i and line %i column %i"