Skip to content

Commit

Permalink
instead of using a potentially wrong config for argument nodes, check…
Browse files Browse the repository at this point in the history
… if the node.Expr is an AppSingleParenArg and just be always atomic in that case when writing the FunctionExpr
  • Loading branch information
dawedawe committed May 30, 2024
1 parent 9dda7f0 commit 2fe8f49
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
27 changes: 27 additions & 0 deletions src/Fantomas.Core.Tests/DotLambdaTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,30 @@ let ``idempotency problem when _.property shorthand quoted, 3050`` () =
"""
"ABC" |> _.``to Lower``()
"""

[<Test>]
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 ())
"""
16 changes: 3 additions & 13 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2fe8f49

Please sign in to comment.