Skip to content

Commit

Permalink
Fix #2954 by using mkIdent in SynPat.OptionalVal (#2956)
Browse files Browse the repository at this point in the history
  • Loading branch information
jindraivanek authored Sep 12, 2023
1 parent 369faf8 commit 74b1812
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
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

0 comments on commit 74b1812

Please sign in to comment.