Skip to content

Commit

Permalink
Type with implicit constructor and generic type constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Nov 25, 2022
1 parent a7cd66e commit 38f56ea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Fantomas.Core.Tests/DallasTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1638,3 +1638,28 @@ let create size : ImmutableArray<'T>.Builder = ImmutableArray.CreateBuilder(size
"""
let create size : ImmutableArray<'T>.Builder = ImmutableArray.CreateBuilder(size)
"""

[<Test>]
let ``type with implicit constructor and generic type constraints`` () =
formatSourceString
false
"""
[<System.Diagnostics.DebuggerDisplay "Count = {Count}">]
[<Sealed>]
type internal Set<'T, 'ComparerTag> when 'ComparerTag :> IComparer<'T>(comparer: IComparer<'T>, tree: SetTree<'T>) =
static let refresh (s: Set<_, _>) t =
Set<_, _>(comparer = s.Comparer, tree = t)
"""
config
|> prepend newline
|> should
equal
"""
[<System.Diagnostics.DebuggerDisplay "Count = {Count}">]
[<Sealed>]
type internal Set<'T, 'ComparerTag> when 'ComparerTag :> IComparer<'T>(comparer: IComparer<'T>, tree: SetTree<'T>) =
static let refresh (s: Set<_, _>) t =
Set<_, _>(comparer = s.Comparer, tree = t)
"""
1 change: 1 addition & 0 deletions src/Fantomas.Core/CodePrinter2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3131,6 +3131,7 @@ let genTypeWithImplicitConstructor (typeName: TypeNameNode) (implicitConstructor
+> sepSpace
+> genAccessOpt typeName.Accessibility
+> genTypeAndParam (genIdentListNode typeName.Identifier) typeName.TypeParameters
+> onlyIfNot typeName.Constraints.IsEmpty (sepSpace +> genTypeConstraints typeName.Constraints)
+> leadingExpressionIsMultiline
(optSingle (fun imCtor -> sepSpaceBeforeClassConstructor +> genImplicitConstructor imCtor) implicitConstructor)
(fun isMulti ctx ->
Expand Down

0 comments on commit 38f56ea

Please sign in to comment.