Skip to content

Commit

Permalink
fix idempotency for single case union w/o pipe (#3116)
Browse files Browse the repository at this point in the history
* fix idempotency for single case union w/o pipe

* update changelog

* Avoid indexed list access.

* Add new version

---------

Co-authored-by: nojaf <[email protected]>
  • Loading branch information
joprice and nojaf authored Sep 10, 2024
1 parent 87a6577 commit ceb1fa2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 6.3.13 - 2024-09-10

### Fixed
* Idempotency problem when adding members to a single case union without a pipe [#3102](https://github.com/fsprojects/fantomas/issues/3102)

## 6.3.12 - 2024-09-05

### Fixed
Expand Down
39 changes: 39 additions & 0 deletions src/Fantomas.Core.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3643,3 +3643,42 @@ type FSharpChecker with
: Async<(FSharpParseFileResults * ParsedInput * FSharpCheckFileResults) option> =
()
"""

[<Test>]
let ``single member union extensions without pipe, 3102`` () =
formatSourceString
"""
type X = X
with
static member x = 1
"""
config
|> prepend newline
|> should
equal
"""
type X = X
with
static member x = 1
"""

[<Test>]
let ``single member union extensions without pipe idempotent, 3102`` () =
formatSourceString
"""
type X = X
with
static member x = 1
"""
config
|> prepend newline
|> should
equal
"""
type X = X
with
static member x = 1
"""
20 changes: 10 additions & 10 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3585,16 +3585,16 @@ let genTypeDefn (td: TypeDefn) =
| _ ->
header
+> sepSpaceOrIndentAndNlnIfExpressionExceedsPageWidth (genType node.Type)
+> onlyIf
hasMembers
(optSingle
(fun withNode ->
indentSepNlnUnindent (
genSingleTextNode withNode
+> onlyIfCtx (fun ctx -> ctx.Config.NewlineBetweenTypeDefinitionAndMembers) sepNln
+> indentSepNlnUnindent (genMemberDefnList members)
))
typeName.WithKeyword)
+> (match List.tryHead members, typeName.WithKeyword with
| Some firstMember, Some withNode ->
indentSepNlnUnindent (
genSingleTextNode withNode
+> onlyIfCtx
(fun ctx -> ctx.Config.NewlineBetweenTypeDefinitionAndMembers)
(sepNlnUnlessContentBefore (MemberDefn.Node firstMember))
+> indentSepNlnUnindent (genMemberDefnList members)
)
| _ -> sepNone)
|> genNode node)
ctx
| TypeDefn.Explicit node ->
Expand Down

0 comments on commit ceb1fa2

Please sign in to comment.