Skip to content

Commit

Permalink
Add and keyword between multiple member constraints. Fixes fsprojects…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Jun 12, 2020
1 parent 11370c3 commit cdf5033
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/Fantomas.Tests/SignatureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -581,4 +581,21 @@ namespace Bar
type A =
internal { ALongIdentifier: string
YetAnotherLongIdentifier: bool }
"""

[<Test>]
let ``multiple constraints on function declaration, 886`` () =
formatSourceString true """namespace Blah
module Foo =
val inline sum : ('a -> ^value) -> 'a Foo -> ^value
when ^value : (static member (+) : ^value * ^value -> ^value) and ^value : (static member Zero : ^value)
""" config
|> prepend newline
|> should equal """
namespace Blah
module Foo =
val inline sum: ('a -> ^value) -> 'a Foo -> ^value
when ^value: (static member (+): ^value * ^value -> ^value) and ^value: (static member Zero: ^value)
"""
5 changes: 3 additions & 2 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2262,8 +2262,9 @@ and genConstraints astContext (t: SynType) =
match t with
| TWithGlobalConstraints(t, tcs) ->
genTypeByLookup astContext t
+> onlyIf (List.isNotEmpty tcs) (!- " when ")
+> col sepSpace tcs (genTypeConstraint astContext)
+> sepSpaceOrNlnIfExpressionExceedsPageWidth
(ifElse (List.isNotEmpty tcs) (!- "when ") sepSpace
+> col wordAnd tcs (genTypeConstraint astContext))
| _ -> sepNone

and genTyparDecl astContext (TyparDecl(ats, tp)) =
Expand Down
6 changes: 6 additions & 0 deletions src/Fantomas/Context.fs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,12 @@ let internal sepSpaceOrIndentAndNlnIfExpressionExceedsPageWidth expr (ctx:Contex
(indent +> sepNln) unindent // before and after for long expressions
expr ctx

let internal sepSpaceOrNlnIfExpressionExceedsPageWidth expr (ctx:Context) =
expressionExceedsPageWidth
sepSpace sepNone // before and after for short expressions
sepNln unindent // before and after for long expressions
expr ctx

let internal autoNlnIfExpressionExceedsPageWidth expr (ctx: Context) =
expressionExceedsPageWidth
sepNone sepNone // before and after for short expressions
Expand Down

0 comments on commit cdf5033

Please sign in to comment.