Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parens: Keep parens for problematic exprs in $"{(…):N0}", $"{(…),-3}", etc. #16578

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
brianrourkeboll marked this conversation as resolved.
Show resolved Hide resolved
| 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
Loading