diff --git a/CHANGELOG.md b/CHANGELOG.md index db32d124e1..b356ead417 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Fantomas.Tests/NewlineBetweenTypeDefinitionAndMembersTests.fs b/src/Fantomas.Tests/NewlineBetweenTypeDefinitionAndMembersTests.fs index 4c5d6fbb60..8e04d5c3ff 100644 --- a/src/Fantomas.Tests/NewlineBetweenTypeDefinitionAndMembersTests.fs +++ b/src/Fantomas.Tests/NewlineBetweenTypeDefinitionAndMembersTests.fs @@ -405,3 +405,26 @@ type A = | B x -> x | _ -> failwith "shouldn't happen" """ + +[] +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 +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index ea9a6130ee..308db3d8c9 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -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