From 74b18128efc71498a4dcdbae2c3d92c8eae20e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jind=C5=99ich=20Iv=C3=A1nek?= Date: Tue, 12 Sep 2023 14:35:29 +0200 Subject: [PATCH] Fix #2954 by using mkIdent in SynPat.OptionalVal (#2956) --- CHANGELOG.md | 5 +++++ src/Fantomas.Core.Tests/TypeDeclarationTests.fs | 17 +++++++++++++++++ src/Fantomas.Core/ASTTransformer.fs | 4 +++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61dd38743d..0fe7020e8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Fantomas.Core.Tests/TypeDeclarationTests.fs b/src/Fantomas.Core.Tests/TypeDeclarationTests.fs index 914d15faa0..a61e67990e 100644 --- a/src/Fantomas.Core.Tests/TypeDeclarationTests.fs +++ b/src/Fantomas.Core.Tests/TypeDeclarationTests.fs @@ -3593,6 +3593,23 @@ type ArrayBuffer = abstract slice: ``begin``: int * ?``end``: int -> ArrayBuffer """ +[] +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`` +""" + [] let ``trivia before comma in primary constructor`` () = formatSourceString diff --git a/src/Fantomas.Core/ASTTransformer.fs b/src/Fantomas.Core/ASTTransformer.fs index 9e5ea201a8..a1b397ed7b 100644 --- a/src/Fantomas.Core/ASTTransformer.fs +++ b/src/Fantomas.Core/ASTTransformer.fs @@ -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,