Skip to content

Commit

Permalink
Respect the order of type name. Fixes fsprojects#1018.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Aug 21, 2020
1 parent 8665356 commit 6188d1e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Fantomas.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1678,3 +1678,9 @@ type Box() =
// If there's no get/set, the comment is preserved
member x.hello = "world"
"""

[<Test>]
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
"""
6 changes: 5 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6188d1e

Please sign in to comment.