Skip to content

Can't format fragment of source code with #if element, and keyword, and triple-slash comment #2360

@knocte

Description

@knocte

Issue created from fantomas-online

Code

module Primitives =
    type BlockHeight =
        | BlockHeight of uint32 

    /// **Description**
    ///
    /// 16bit relative block height used for `OP_CSV` locks,
    /// Since OP_CSV allow only block number of 0 ~ 65535, it is safe
    /// to restrict into the range smaller than BlockHeight
    and
#if !NoDUsAsStructs
        [<Struct>]
#endif
        BlockHeightOffset16 =
            | BlockHeightOffset16 of uint16

Error

Fantomas.Core.FormatConfig+FormatException: Fantomas is trying to format the input multiple times due to the detect of multiple defines.
There is a problem with merging all the code back together.
[] has 2 fragments
[NoDUsAsStructs] has 3 fragments
Please raise an issue at https://fsprojects.github.io/fantomas-tools/#/fantomas/preview.
   at Fantomas.Core.CodeFormatterImpl.format@87-5.Invoke(FSharpList`1 results) in /_//src/Fantomas.Core/CodeFormatterImpl.fs:line 108
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 465
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 104

Problem description

Please describe here the Fantomas problem you encountered.
Check out our Contribution Guidelines.

Extra information

  • The formatted result breaks my code.
  • The formatted result gives compiler warnings.
  • I or my company would be willing to help fix this.

Options

Fantomas master branch at 2022-07-11T16:44:40Z - 98a7449

Default Fantomas configuration

Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions