diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cc55cc0f9..016611ed1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## [Unreleased] +## [6.0.4] - 2023-06-02 ### Changed * Update FCS to 'Prototype signature files for lex files', commit 5b74995780a0e9d24a5db025e68b31e6d910f71f @@ -8,6 +8,7 @@ ### Fixed * Missing space before arrow. [#2888](https://github.com/fsprojects/fantomas/issues/2888) * Cons pattern in let bindings is converted to invalid code. [#1996](https://github.com/fsprojects/fantomas/issues/1996) +* Trivia after infix operator is not restored correctly. [#2887](https://github.com/fsprojects/fantomas/issues/2887) ## [6.0.3] - 2023-05-14 diff --git a/src/Fantomas.Core.Tests/CommentTests.fs b/src/Fantomas.Core.Tests/CommentTests.fs index 996c811baa..1edd288d95 100644 --- a/src/Fantomas.Core.Tests/CommentTests.fs +++ b/src/Fantomas.Core.Tests/CommentTests.fs @@ -2612,3 +2612,45 @@ let (* this comment disappears after formatting *) a = [] """ let (* this comment disappears after formatting *) a = [] """ + +[] +let ``trivia after infix operator is not restored correctly, 2887`` () = + formatSourceString + false + """ +let EnableHeapTerminationOnCorruption() = + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.OSVersion.Version.Major >= 6 && // If OS is Vista or higher + Environment.Version.Major < 3) then // and CLR not 3.0 or higher + let HeapEnableTerminationOnCorruption = 1u : uint32 + if not (HeapSetInformation(GetProcessHeap(), HeapEnableTerminationOnCorruption, UIntPtr.Zero, UIntPtr.Zero)) then + raise (System.Security.SecurityException( + "Unable to enable unmanaged process execution option TerminationOnCorruption. " + + "HeapSetInformation() returned FALSE; LastError = 0x" + + GetLastError().ToString("X").PadLeft(8, '0') + ".")) +""" + config + |> prepend newline + |> should + equal + """ +let EnableHeapTerminationOnCorruption () = + if + (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) + && Environment.OSVersion.Version.Major >= 6 + && // If OS is Vista or higher + Environment.Version.Major < 3) + then // and CLR not 3.0 or higher + let HeapEnableTerminationOnCorruption = 1u: uint32 + + if + not (HeapSetInformation(GetProcessHeap(), HeapEnableTerminationOnCorruption, UIntPtr.Zero, UIntPtr.Zero)) + then + raise ( + System.Security.SecurityException( + "Unable to enable unmanaged process execution option TerminationOnCorruption. " + + "HeapSetInformation() returned FALSE; LastError = 0x" + + GetLastError().ToString("X").PadLeft(8, '0') + + "." + ) + ) +""" diff --git a/src/Fantomas.Core/CodePrinter.fs b/src/Fantomas.Core/CodePrinter.fs index 818166255c..5bd47fe009 100644 --- a/src/Fantomas.Core/CodePrinter.fs +++ b/src/Fantomas.Core/CodePrinter.fs @@ -772,7 +772,7 @@ let genExpr (e: Expr) = +> sepNln +> col sepNln es (fun (operator, e) -> genSingleTextNode operator - +> sepSpace + +> sepNlnWhenWriteBeforeNewlineNotEmptyOr sepSpace +> (fun ctx -> match e with | Expr.Lambda _ when