From 6188d1e4bbcd6fc93c2e98f5c4e21a2d74b801c8 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 21 Aug 2020 14:06:09 +0200 Subject: [PATCH] Respect the order of type name. Fixes #1018. --- src/Fantomas.Tests/TypeDeclarationTests.fs | 6 ++++++ src/Fantomas/CodePrinter.fs | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Fantomas.Tests/TypeDeclarationTests.fs b/src/Fantomas.Tests/TypeDeclarationTests.fs index 8e2dbef8bc..6c34e19152 100644 --- a/src/Fantomas.Tests/TypeDeclarationTests.fs +++ b/src/Fantomas.Tests/TypeDeclarationTests.fs @@ -1678,3 +1678,9 @@ type Box() = // If there's no get/set, the comment is preserved member x.hello = "world" """ + +[] +let ``union type with constraint`` () = + formatSourceString false """type 'a t when 'a :> IDisposable = T of 'a option""" config + |> should equal """type 'a t when 'a :> IDisposable = T of 'a option +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index e879ca1c6c..c4fce430fc 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -539,7 +539,11 @@ and genTypeAndParam astContext typeName tds tcs preferPostfix = +> colPre (!- " when ") wordAnd tcs (genTypeConstraint astContext) -- closeSep) if List.isEmpty tds then !- typeName elif preferPostfix then !- typeName +> types "<" ">" - elif List.atMostOne tds then types "" "" -- " " -- typeName + elif List.atMostOne tds then + genTyparDecl { astContext with IsFirstTypeParam = true } (List.head tds) + +> sepSpace + -- typeName + +> colPre (!- " when ") wordAnd tcs (genTypeConstraint astContext) else types "(" ")" -- " " -- typeName and genTypeParamPostfix astContext tds tcs = genTypeAndParam astContext "" tds tcs true