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

Fix 2954 by using mkIdent in SynPat.OptionalVal #2956

Merged
merged 1 commit into from
Sep 12, 2023
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [Unreleased]

### Fixed
* Backticks in optional parameter gets removed [#2954](https://github.com/fsprojects/fantomas/issues/2954)

## 6.2.0 - 2023-08-29

### Changed
Expand Down
17 changes: 17 additions & 0 deletions src/Fantomas.Core.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3593,6 +3593,23 @@ type ArrayBuffer =
abstract slice: ``begin``: int * ?``end``: int -> ArrayBuffer
"""

[<Test>]
let ``optional member parameter with ticks, 2954`` () =
formatSourceString
false
"""
type C() =
static member foo(?``type``) = ``type``
"""
config
|> prepend newline
|> should
equal
"""
type C() =
static member foo(?``type``) = ``type``
"""

[<Test>]
let ``trivia before comma in primary constructor`` () =
formatSourceString
Expand Down
4 changes: 3 additions & 1 deletion src/Fantomas.Core/ASTTransformer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,9 @@ let mkPat (creationAide: CreationAide) (p: SynPat) =
let patternRange = p.Range

match p with
| SynPat.OptionalVal(ident, _) -> stn $"?{ident.idText}" patternRange |> Pattern.OptionalVal
| SynPat.OptionalVal(ident, _) ->
let identNode = mkIdent ident
SingleTextNode($"?{identNode.Text}", patternRange) |> Pattern.OptionalVal
| PatParameter(ats, pat, t) ->
PatParameterNode(
mkAttributes creationAide ats,
Expand Down