Skip to content

Commit 9ae94bb

Browse files
Parens: Keep parens for problematic exprs in $"{(…):N0}", $"{(…),-3}", etc. (#16578)
* Keep parens for problematic exprs in `$"{(…):f}"` * Update release notes * Better * Sanity
1 parent 615475b commit 9ae94bb

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

docs/release-notes/.FSharp.Compiler.Service/8.0.300.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Code generated files with > 64K methods and generated symbols crash when loaded. Use infered sequence points for debugging. ([Issue #16399](https://github.com/dotnet/fsharp/issues/16399), [#PR 16514](https://github.com/dotnet/fsharp/pull/16514))
44
* `nameof Module` expressions and patterns are processed to link files in `--test:GraphBasedChecking`. ([PR #16550](https://github.com/dotnet/fsharp/pull/16550))
55
* Graph Based Checking doesn't throw on invalid parsed input so it can be used for IDE scenarios ([PR #16575](https://github.com/dotnet/fsharp/pull/16575))
6+
* Keep parens for problematic exprs (`if`, `match`, etc.) in `$"{(…):N0}"`, `$"{(…),-3}"`, etc. ([PR #16578](https://github.com/dotnet/fsharp/pull/16578))
67

78
### Added
89

src/Compiler/Service/SynExpr.fs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,9 @@ module SynExpr =
423423
| SynExpr.MatchLambda(matchClauses = Last(SynMatchClause(resultExpr = expr)))
424424
| SynExpr.MatchBang(clauses = Last(SynMatchClause(resultExpr = expr)))
425425
| SynExpr.TryWith(withCases = Last(SynMatchClause(resultExpr = expr)))
426-
| SynExpr.TryFinally(finallyExpr = expr) -> loop expr
426+
| SynExpr.TryFinally(finallyExpr = expr)
427+
| SynExpr.Do(expr = expr)
428+
| SynExpr.DoBang(expr = expr) -> loop expr
427429
| _ -> ValueNone
428430

429431
loop
@@ -810,6 +812,12 @@ module SynExpr =
810812
->
811813
true
812814

815+
| SynExpr.InterpolatedString(contents = contents), (SynExpr.Tuple(isStruct = false) | Dangling.Problematic _) ->
816+
contents
817+
|> List.exists (function
818+
| SynInterpolatedStringPart.FillExpr(qualifiers = Some _) -> true
819+
| _ -> false)
820+
813821
| SynExpr.Record(copyInfo = Some(SynExpr.Paren(expr = Is inner), _)), Dangling.Problematic _
814822
| SynExpr.AnonRecd(copyInfo = Some(SynExpr.Paren(expr = Is inner), _)), Dangling.Problematic _ -> true
815823

vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,24 @@ in x
800800
"$\"{(id 3)}\"", "$\"{id 3}\""
801801
"$\"{(x)}\"", "$\"{x}\""
802802

803+
"$\"{(if true then 1 else 0)}\"", "$\"{if true then 1 else 0}\""
804+
"$\"{(if true then 1 else 0):N0}\"", "$\"{(if true then 1 else 0):N0}\""
805+
"$\"{(if true then 1 else 0),-3}\"", "$\"{(if true then 1 else 0),-3}\""
806+
"$\"{(match () with () -> 1):N0}\"", "$\"{(match () with () -> 1):N0}\""
807+
"$\"{(match () with () -> 1),-3}\"", "$\"{(match () with () -> 1),-3}\""
808+
"$\"{(try () with _ -> 1):N0}\"", "$\"{(try () with _ -> 1):N0}\""
809+
"$\"{(try () with _ -> 1),-3}\"", "$\"{(try () with _ -> 1),-3}\""
810+
"$\"{(try 1 finally ()):N0}\"", "$\"{(try 1 finally ()):N0}\""
811+
"$\"{(try 1 finally ()),-3}\"", "$\"{(try 1 finally ()),-3}\""
812+
"$\"{(let x = 3 in x):N0}\"", "$\"{(let x = 3 in x):N0}\""
813+
"$\"{(let x = 3 in x),-3}\"", "$\"{(let x = 3 in x),-3}\""
814+
"$\"{(do (); 3):N0}\"", "$\"{(do (); 3):N0}\""
815+
"$\"{(do (); 3),-3}\"", "$\"{(do (); 3),-3}\""
816+
"$\"{(x <- 3):N0}\"", "$\"{(x <- 3):N0}\""
817+
"$\"{(x <- 3),-3}\"", "$\"{(x <- 3),-3}\""
818+
"$\"{(1, 2):N0}\"", "$\"{(1, 2):N0}\""
819+
"$\"{(1, 2),-3}\"", "$\"{(1, 2),-3}\""
820+
803821
"""
804822
$"{(3 + LanguagePrimitives.GenericZero<int>):N0}"
805823
""",

0 commit comments

Comments
 (0)