Skip to content

Commit

Permalink
Parens: Keep parens for problematic exprs in $"{(…):N0}", `$"{(…),-…
Browse files Browse the repository at this point in the history
…3}"`, etc. (#16578)

* Keep parens for problematic exprs in `$"{(…):f}"`

* Update release notes

* Better

* Sanity
  • Loading branch information
brianrourkeboll authored Jan 26, 2024
1 parent 615475b commit 9ae94bb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/8.0.300.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* 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))
* `nameof Module` expressions and patterns are processed to link files in `--test:GraphBasedChecking`. ([PR #16550](https://github.com/dotnet/fsharp/pull/16550))
* 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))
* Keep parens for problematic exprs (`if`, `match`, etc.) in `$"{(…):N0}"`, `$"{(…),-3}"`, etc. ([PR #16578](https://github.com/dotnet/fsharp/pull/16578))

### Added

Expand Down
10 changes: 9 additions & 1 deletion src/Compiler/Service/SynExpr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,9 @@ module SynExpr =
| SynExpr.MatchLambda(matchClauses = Last(SynMatchClause(resultExpr = expr)))
| SynExpr.MatchBang(clauses = Last(SynMatchClause(resultExpr = expr)))
| SynExpr.TryWith(withCases = Last(SynMatchClause(resultExpr = expr)))
| SynExpr.TryFinally(finallyExpr = expr) -> loop expr
| SynExpr.TryFinally(finallyExpr = expr)
| SynExpr.Do(expr = expr)
| SynExpr.DoBang(expr = expr) -> loop expr
| _ -> ValueNone

loop
Expand Down Expand Up @@ -810,6 +812,12 @@ module SynExpr =
->
true

| SynExpr.InterpolatedString(contents = contents), (SynExpr.Tuple(isStruct = false) | Dangling.Problematic _) ->
contents
|> List.exists (function
| SynInterpolatedStringPart.FillExpr(qualifiers = Some _) -> true
| _ -> false)

| SynExpr.Record(copyInfo = Some(SynExpr.Paren(expr = Is inner), _)), Dangling.Problematic _
| SynExpr.AnonRecd(copyInfo = Some(SynExpr.Paren(expr = Is inner), _)), Dangling.Problematic _ -> true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,24 @@ in x
"$\"{(id 3)}\"", "$\"{id 3}\""
"$\"{(x)}\"", "$\"{x}\""

"$\"{(if true then 1 else 0)}\"", "$\"{if true then 1 else 0}\""
"$\"{(if true then 1 else 0):N0}\"", "$\"{(if true then 1 else 0):N0}\""
"$\"{(if true then 1 else 0),-3}\"", "$\"{(if true then 1 else 0),-3}\""
"$\"{(match () with () -> 1):N0}\"", "$\"{(match () with () -> 1):N0}\""
"$\"{(match () with () -> 1),-3}\"", "$\"{(match () with () -> 1),-3}\""
"$\"{(try () with _ -> 1):N0}\"", "$\"{(try () with _ -> 1):N0}\""
"$\"{(try () with _ -> 1),-3}\"", "$\"{(try () with _ -> 1),-3}\""
"$\"{(try 1 finally ()):N0}\"", "$\"{(try 1 finally ()):N0}\""
"$\"{(try 1 finally ()),-3}\"", "$\"{(try 1 finally ()),-3}\""
"$\"{(let x = 3 in x):N0}\"", "$\"{(let x = 3 in x):N0}\""
"$\"{(let x = 3 in x),-3}\"", "$\"{(let x = 3 in x),-3}\""
"$\"{(do (); 3):N0}\"", "$\"{(do (); 3):N0}\""
"$\"{(do (); 3),-3}\"", "$\"{(do (); 3),-3}\""
"$\"{(x <- 3):N0}\"", "$\"{(x <- 3):N0}\""
"$\"{(x <- 3),-3}\"", "$\"{(x <- 3),-3}\""
"$\"{(1, 2):N0}\"", "$\"{(1, 2):N0}\""
"$\"{(1, 2),-3}\"", "$\"{(1, 2),-3}\""

"""
$"{(3 + LanguagePrimitives.GenericZero<int>):N0}"
""",
Expand Down

0 comments on commit 9ae94bb

Please sign in to comment.