From 38eaf20ac9e614b852547d2f2fc640a3541bcea1 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Mon, 5 May 2025 18:15:51 -0400 Subject: [PATCH 1/3] Keep parens around records in interpolated strings --- src/Compiler/Service/SynExpr.fs | 2 ++ .../CodeFixes/RemoveUnnecessaryParenthesesTests.fs | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Compiler/Service/SynExpr.fs b/src/Compiler/Service/SynExpr.fs index 5981dd5b286..c86da90d2b3 100644 --- a/src/Compiler/Service/SynExpr.fs +++ b/src/Compiler/Service/SynExpr.fs @@ -1078,6 +1078,8 @@ module SynExpr = | SynExpr.Sequential(expr1 = SynExpr.Paren(expr = Is inner); expr2 = expr2), _ when innerBindingsWouldShadowOuter inner expr2 -> true + | SynExpr.InterpolatedString _, SynExpr.Record _ + | SynExpr.InterpolatedString _, SynExpr.AnonRecd _ | SynExpr.InterpolatedString _, SynExpr.Sequential _ | SynExpr.InterpolatedString _, SynExpr.Tuple(isStruct = false) -> true diff --git a/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs b/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs index 224849a59e2..8ee26c35a9e 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs @@ -1390,6 +1390,20 @@ in x $"{3 + LanguagePrimitives.GenericZero :N0}" """ + """ + $"{({ A = 3 })}" + """, + """ + $"{({ A = 3 })}" + """ + + """ + $"{({| A = 3 |})}" + """, + """ + $"{({| A = 3 |})}" + """ + // LibraryOnlyILAssembly """(# "ldlen.multi 2 0" array : int #)""", """(# "ldlen.multi 2 0" array : int #)""" From 101d8a3b8f10359ab2b14b924a6f6060df0941d8 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Mon, 5 May 2025 18:19:45 -0400 Subject: [PATCH 2/3] Update release notes --- docs/release-notes/.FSharp.Compiler.Service/9.0.300.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.300.md index e187f285d4b..52cf5eb8350 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.300.md @@ -16,7 +16,7 @@ * Unsafe downcast from `obj` to generic `T` no longer requires `not null` constraint on `T`([Issue #18275](https://github.com/dotnet/fsharp/issues/18275), [PR #18343](https://github.com/dotnet/fsharp/pull/18343)) * Fix "type inference problem too complicated" for SRTP with T:null and T:struct dummy constraint([Issue #18288](https://github.com/dotnet/fsharp/issues/18288), [PR #18345](https://github.com/dotnet/fsharp/pull/18345)) * Fix for missing parse diagnostics in TransparentCompiler.ParseAndCheckProject ([PR #18366](https://github.com/dotnet/fsharp/pull/18366)) -* Miscellanous parentheses analyzer fixes. ([PR #18350](https://github.com/dotnet/fsharp/pull/18350)) +* Miscellanous parentheses analyzer fixes. ([PR #18350](https://github.com/dotnet/fsharp/pull/18350), [PR #18534](https://github.com/dotnet/fsharp/pull/18534)) * Fix duplicate parse error reporting for GetBackgroundCheckResultsForFileInProject ([Issue #18379](https://github.com/dotnet/fsharp/issues/18379) [PR #18380](https://github.com/dotnet/fsharp/pull/18380)) * Fix MethodDefNotFound when compiling code invoking delegate with option parameter ([Issue #5171](https://github.com/dotnet/fsharp/issues/5171), [PR #18385](https://github.com/dotnet/fsharp/pull/18385)) * Fix #r nuget ..." downloads unneeded packages ([Issue #18231](https://github.com/dotnet/fsharp/issues/18231), [PR #18393](https://github.com/dotnet/fsharp/pull/18393)) From 352fd34a01b9cb38d726ed59a0be5279f9d53578 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Mon, 5 May 2025 18:29:44 -0400 Subject: [PATCH 3/3] Keep parens around seq-less seq exprs in interpolated strings --- src/Compiler/Service/SynExpr.fs | 6 ++++++ .../CodeFixes/RemoveUnnecessaryParenthesesTests.fs | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/Compiler/Service/SynExpr.fs b/src/Compiler/Service/SynExpr.fs index c86da90d2b3..52c10e8a7a5 100644 --- a/src/Compiler/Service/SynExpr.fs +++ b/src/Compiler/Service/SynExpr.fs @@ -1078,8 +1078,14 @@ module SynExpr = | SynExpr.Sequential(expr1 = SynExpr.Paren(expr = Is inner); expr2 = expr2), _ when innerBindingsWouldShadowOuter inner expr2 -> true + // $"{({ A = 3 })}" + // $"{({| A = 3 |})}" + // $"{({1..10})}" + // $"{(();1)}" + // $"{(1,2)}" | SynExpr.InterpolatedString _, SynExpr.Record _ | SynExpr.InterpolatedString _, SynExpr.AnonRecd _ + | SynExpr.InterpolatedString _, SynExpr.ComputationExpr _ | SynExpr.InterpolatedString _, SynExpr.Sequential _ | SynExpr.InterpolatedString _, SynExpr.Tuple(isStruct = false) -> true diff --git a/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs b/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs index 8ee26c35a9e..a7b90207877 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs @@ -1404,6 +1404,13 @@ in x $"{({| A = 3 |})}" """ + """ + $"{({ 1..10 })}" + """, + """ + $"{({ 1..10 })}" + """ + // LibraryOnlyILAssembly """(# "ldlen.multi 2 0" array : int #)""", """(# "ldlen.multi 2 0" array : int #)"""