Skip to content

Commit

Permalink
Fix newline idempotency issue with multiline abstract members without…
Browse files Browse the repository at this point in the history
… constraints by adding additional check (fsprojects#2183)
  • Loading branch information
dawedawe authored and jindraivanek committed Apr 9, 2022
1 parent 3547700 commit 32decdd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixed
* SRTP or condition disappear when non-generic type is used. [#2168](https://github.com/fsprojects/fantomas/issues/2168)
* Multiline AbstractSlot without constraints introduces newline [#2175](https://github.com/fsprojects/fantomas/issues/2175)

## [4.7.5] - 2022-03-27

Expand Down
23 changes: 23 additions & 0 deletions src/Fantomas.Tests/NewlineBetweenTypeDefinitionAndMembersTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,26 @@ type A =
| B x -> x
| _ -> failwith "shouldn't happen"
"""

[<Test>]
let ``multiline abstract member without constraints, 2175`` () =
formatSourceString
false
"""
type FuseSortFunctionItem =
abstract Item: key: string -> U2<{| ``$``: string |}, ResizeArray<{| ``$``: string; idx: float |}>> with get, set
abstract X : int
"""
{ config with MaxLineLength = 60 }
|> prepend newline
|> should
equal
"""
type FuseSortFunctionItem =
abstract Item:
key: string ->
U2<{| ``$``: string |}, ResizeArray<{| ``$``: string
idx: float |}>> with get, set
abstract X: int
"""
7 changes: 6 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4835,7 +4835,12 @@ and genMemberDefn astContext node =
+> ifElse hasGenerics sepColonWithSpacesFixed sepColon
+> autoIndentAndNlnIfExpressionExceedsPageWidth (genTypeList astContext namedArgs)
-- genPropertyKind (not isFunctionProperty) mf.MemberKind
+> autoIndentAndNlnIfExpressionExceedsPageWidth (genConstraints astContext t vi)
+> onlyIf
(match t with
| TWithGlobalConstraints _ -> true
| _ -> false)
autoIndentAndNlnIfExpressionExceedsPageWidth
(genConstraints astContext t vi)

| md -> failwithf "Unexpected member definition: %O" md
|> genTriviaFor (synMemberDefnToFsAstType node) node.Range
Expand Down

0 comments on commit 32decdd

Please sign in to comment.