Skip to content

Multiple #if directives inside list #3397

Description

@nojaf

Issue created from fantomas-online

Code

module M

let tests () =
  let tfms = [
#if NET8_0_OR_GREATER
    "net8.0"
#endif
#if NET9_0_OR_GREATER
    "net9.0"
#endif
  ]
  tfms

Error

Fantomas.Core.DefineParseException: Parsing failed for define combination(s): no defines.
   at Fantomas.Core.CodeFormatterImpl.parse@61-11.Invoke(FSharpResult`2[] results) in /_//src/Fantomas.Core/CodeFormatterImpl.fs:line 69
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\async.fs:line 527
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\fsharp\src\FSharp.Core\async.fs:line 112

Problem description

error 58 at ]: "this token is offside of context started at position (4:3)" for some case.
Trivia stuff.

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.
  • I would like a release if this problem is solved.

Options

Fantomas main branch at 2026-08-19T11:26:11Z - 25e2376

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.

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