fsprojects / fantomas

FSharp source code formatter
https://fsprojects.github.io/fantomas
Other
770 stars 193 forks source link

Trivia after infix operator is not restored correctly #2887

Closed nojaf closed 1 year ago

nojaf commented 1 year ago

Issue created from fantomas-online

Code

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') + "."))

Result

let EnableHeapTerminationOnCorruption () =
    if
        (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
         && Environment.OSVersion.Version.Major >= 6
         && Environment // If OS is Vista or higher
         .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')
                    + "."
                )
            )

Problem description

&& // If OS is Vista or higher is not restored correctly leading to an offset problem. I'm not sure why the online tool didn't pick up this problem after the first format.

Extra information

Options

Fantomas main branch at 6/1/2023

Default Fantomas configuration

Did you know that you can ignore files when formatting by using a .fantomasignore file? PS: It's unlikely that someone else will solve your specific issue, as it's something that you have a personal stake in.