From 36dfd44fcbab3811cbfce914bbe744b6da060c39 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Wed, 6 Dec 2023 11:10:40 -0500 Subject: [PATCH 1/3] Keep parens in apps in dot-lambdas --- src/Compiler/Service/ServiceAnalysis.fs | 3 ++- .../CodeFixes/RemoveUnnecessaryParenthesesTests.fs | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Service/ServiceAnalysis.fs b/src/Compiler/Service/ServiceAnalysis.fs index 09dc977ec81..10208d7a47c 100644 --- a/src/Compiler/Service/ServiceAnalysis.fs +++ b/src/Compiler/Service/ServiceAnalysis.fs @@ -1207,10 +1207,11 @@ module UnnecessaryParentheses = // // x.M(y).N z // x.M(y).[z] + // _.M(x) // (f x)[z] // (f(x))[z] // x.M(y)[z] - | SynExpr.Paren _, SyntaxNode.SynExpr(SynExpr.App _) :: SyntaxNode.SynExpr(SynExpr.DotGet _ | SynExpr.DotIndexedGet _) :: _ + | SynExpr.Paren _, SyntaxNode.SynExpr(SynExpr.App _) :: SyntaxNode.SynExpr(SynExpr.DotGet _ | SynExpr.DotIndexedGet _ | SynExpr.DotLambda _) :: _ | SynExpr.Paren(expr = SynExpr.App _), SyntaxNode.SynExpr(SynExpr.App(argExpr = SynExpr.ArrayOrListComputed(isArray = false))) :: _ | SynExpr.Paren _, diff --git a/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs b/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs index 27bce12bb2d..2f261a542fa 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs @@ -616,7 +616,8 @@ in x "([] : int list).Length", "([] : int list).Length" // DotLambda - "[{| A = x |}] |> List.map (_.A)", "[{| A = x |}] |> List.map _.A" + """_.ToString("x")""", """_.ToString("x")""" + """_.ToString(("x"))""", """_.ToString("x")""" // DotSet "(ref 3).Value <- (3)", "(ref 3).Value <- 3" @@ -1106,6 +1107,8 @@ in x // DotLambda "[{| A = x |}] |> List.map (_.A)", "[{| A = x |}] |> List.map _.A" + """[1..10] |> List.map _.ToString("x")""", """[1..10] |> List.map _.ToString("x")""" + """[1..10] |> List.map _.ToString(("x"))""", """[1..10] |> List.map _.ToString("x")""" // DotSet "id ((ref x).Value <- y)", "id ((ref x).Value <- y)" From 70659436a0f61953e8c50b62206589b98548248b Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Wed, 6 Dec 2023 11:23:53 -0500 Subject: [PATCH 2/3] Fantomas --- src/Compiler/Service/ServiceAnalysis.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Compiler/Service/ServiceAnalysis.fs b/src/Compiler/Service/ServiceAnalysis.fs index 10208d7a47c..8570835e568 100644 --- a/src/Compiler/Service/ServiceAnalysis.fs +++ b/src/Compiler/Service/ServiceAnalysis.fs @@ -1211,7 +1211,8 @@ module UnnecessaryParentheses = // (f x)[z] // (f(x))[z] // x.M(y)[z] - | SynExpr.Paren _, SyntaxNode.SynExpr(SynExpr.App _) :: SyntaxNode.SynExpr(SynExpr.DotGet _ | SynExpr.DotIndexedGet _ | SynExpr.DotLambda _) :: _ + | SynExpr.Paren _, + SyntaxNode.SynExpr(SynExpr.App _) :: SyntaxNode.SynExpr(SynExpr.DotGet _ | SynExpr.DotIndexedGet _ | SynExpr.DotLambda _) :: _ | SynExpr.Paren(expr = SynExpr.App _), SyntaxNode.SynExpr(SynExpr.App(argExpr = SynExpr.ArrayOrListComputed(isArray = false))) :: _ | SynExpr.Paren _, From 596ce1b87d526a2e86a1ea6b35b183f2d4b9aba1 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Wed, 6 Dec 2023 11:30:42 -0500 Subject: [PATCH 3/3] Add entry to FCS release notes --- docs/release-notes/FSharp.Compiler.Service/8.0.200.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/FSharp.Compiler.Service/8.0.200.md b/docs/release-notes/FSharp.Compiler.Service/8.0.200.md index c0d199a7864..057891ec86b 100644 --- a/docs/release-notes/FSharp.Compiler.Service/8.0.200.md +++ b/docs/release-notes/FSharp.Compiler.Service/8.0.200.md @@ -1,2 +1,3 @@ - Miscellaneous fixes to parens analysis - https://github.com/dotnet/fsharp/pull/16262 -- Fixes #16359 - correctly handle imports with 0 length public key tokens - https://github.com/dotnet/fsharp/pull/16363 \ No newline at end of file +- Parens analysis: keep parens in method calls in dot-lambdas - https://github.com/dotnet/fsharp/pull/16395 +- Fixes #16359 - correctly handle imports with 0 length public key tokens - https://github.com/dotnet/fsharp/pull/16363