Skip to content

Commit

Permalink
Fix idempotency problem when reformatting type declaration with large…
Browse files Browse the repository at this point in the history
… when clause (#2897)

* Fix idempotency problem when reformatting type declaration with large when clause

* Update unit test.

* Add 6.0.5 release version

---------

Co-authored-by: Florian Verdonck <florian.verdonck@outlook.com>
  • Loading branch information
etareduction and nojaf committed Jun 6, 2023
1 parent 838436b commit d8e7276
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [6.0.5] - 2023-06-06

### Fixed
* Idempotency problem when reformatting type declaration with large when clause. [#2896](https://github.com/fsprojects/fantomas/issues/2896)

## [6.0.4] - 2023-06-02

### Changed
Expand Down
27 changes: 27 additions & 0 deletions src/Fantomas.Core.Tests/FunctionDefinitionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1353,3 +1353,30 @@ let inline repro (a: ^``QuotedWithIllegalChar<'T>``) = ()
"""
let inline repro (a: ^``QuotedWithIllegalChar<'T>``) = ()
"""

[<Test>]
let ``multiline member constraints on type parameters, 2896`` () =
formatSourceString
false
"""
let inline func
(arg:
'a when 'a: (member a: int) and 'a: (member b: int) and 'a: (member c: int) and 'a: (member d: int) and 'a: (member e: int))
= 0
"""
config
|> prepend newline
|> should
equal
"""
let inline func
(arg:
'a
when 'a: (member a: int)
and 'a: (member b: int)
and 'a: (member c: int)
and 'a: (member d: int)
and 'a: (member e: int))
=
0
"""
8 changes: 1 addition & 7 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3062,13 +3062,7 @@ let genType (t: Type) =
+> genSingleTextNode node.ClosingParen
|> genNode node
| Type.WithSubTypeConstraint tc -> genTypeConstraint tc
| Type.WithGlobalConstraints node ->
leadingExpressionIsMultiline (genType node.Type) (fun isMultiline ->
if isMultiline then
indentSepNlnUnindent (genTypeConstraints node.TypeConstraints)
else
sepSpaceOrIndentAndNlnIfExpressionExceedsPageWidth (genTypeConstraints node.TypeConstraints))
|> genNode node
| Type.WithGlobalConstraints node -> genType node.Type +> genTypeConstraints node.TypeConstraints |> genNode node
| Type.LongIdent idn -> genIdentListNode idn
| Type.AnonRecord node ->
let genStruct =
Expand Down

0 comments on commit d8e7276

Please sign in to comment.