diff --git a/src/Fantomas.Core.Tests/DotLambdaTests.fs b/src/Fantomas.Core.Tests/DotLambdaTests.fs index ddc72afce..45285c3e3 100644 --- a/src/Fantomas.Core.Tests/DotLambdaTests.fs +++ b/src/Fantomas.Core.Tests/DotLambdaTests.fs @@ -104,3 +104,30 @@ let ``idempotency problem when _.property shorthand quoted, 3050`` () = """ "ABC" |> _.``to Lower``() """ + +[] +let ``idempotency problem when _.Property shorthand with app arg, 3050`` () = + formatSourceString + """ +let Meh () = 1 + +type Bar() = + member this.Foo(v:int):int = v + 1 + +let b = Bar() +b |> _.Foo(Meh ()) +""" + { config with + SpaceBeforeUppercaseInvocation = true } + |> prepend newline + |> should + equal + """ +let Meh () = 1 + +type Bar() = + member this.Foo(v: int) : int = v + 1 + +let b = Bar () +b |> _.Foo(Meh ()) +""" diff --git a/src/Fantomas.Core/CodePrinter.fs b/src/Fantomas.Core/CodePrinter.fs index 1920400b2..658f5fcdd 100644 --- a/src/Fantomas.Core/CodePrinter.fs +++ b/src/Fantomas.Core/CodePrinter.fs @@ -1554,19 +1554,9 @@ let genExpr (e: Expr) = | Expr.Typar node -> genSingleTextNode node | Expr.DotLambda node -> let genDotLambdaExpr expr = - fun ctx -> - let currentConfig = ctx.Config - - let dotLambdaConfig = - { currentConfig with - // override the SpaceBefore[Upper|Lower]caseInvocation to avoid generating breaking code. - // see unit tests for issue 3050`` - SpaceBeforeUppercaseInvocation = false - SpaceBeforeLowercaseInvocation = false } - - genExpr expr { ctx with Config = dotLambdaConfig } - // Restore the existing configuration after printing the DotLambda expression - |> fun ctx -> { ctx with Config = currentConfig } + match expr with + | Expr.AppSingleParenArg p -> genExpr p.FunctionExpr +> genExpr p.ArgExpr // be always atomic, see 3050 + | _ -> genExpr expr genSingleTextNode node.Underscore +> genSingleTextNode node.Dot