Skip to content

Commit

Permalink
Take single tuple parameter in lambda into account to capture lambda …
Browse files Browse the repository at this point in the history
…body. Fixes #1789. (#1790)
  • Loading branch information
nojaf authored Jun 27, 2021
1 parent afc6ead commit 38b556b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/Fantomas.Tests/LambdaTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -897,3 +897,37 @@ let x =
"""
let x = fun _ -> fun _ -> "hello"
"""

[<Test>]
let ``wild card parameters in lambda, 1789`` () =
formatSourceString
false
"""
let elifs =
es
|> List.collect (fun (e1, e2, _, _, _) -> [ visit e1; visit e2 ])
"""
config
|> prepend newline
|> should
equal
"""
let elifs =
es
|> List.collect (fun (e1, e2, _, _, _) -> [ visit e1; visit e2 ])
"""

[<Test>]
let ``leading and trailing wild card parameters in lambda`` () =
formatSourceString
false
"""
List.map (fun (_, _, _, _, body, _) -> visit body) andBangs
"""
config
|> prepend newline
|> should
equal
"""
List.map (fun (_, _, _, _, body, _) -> visit body) andBangs
"""
5 changes: 4 additions & 1 deletion src/Fantomas/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,10 @@ let (|Clause|) (SynMatchClause.Clause (p, eo, e, _, _)) = (p, e, eo)
let (|Lambda|_|) =
function
| SynExpr.Lambda (_, _, _, _, Some (pats, body), range) ->
let maxDepth = List.length pats
let maxDepth =
match pats with
| [ PatParen (PatTuple ts) ] -> List.length ts
| _ -> List.length pats
// find the body expression from the last lambda
let rec visit (currentDepth: int) (e: SynExpr) : SynExpr =
if currentDepth < maxDepth then
Expand Down

0 comments on commit 38b556b

Please sign in to comment.