Skip to content

#nowarn in arbitrary places produces a parsing failure #3263

@xperiandri

Description

@xperiandri

Issue created from fantomas-online

Code

let SingleChoiceTextValueType =
    Define.Object<CustomValue> (
        name = "SingleChoiceTextValue",
        fields = [
#nowarn 25 // Incomplete pattern match
            Define.Field ("options", ListOf StringType, fun _ (SingleChoiceTextValue sctv) -> sctv.Options)
            Define.Field (
                "optionsTranslations",
                ListOf SelectTypeOptionsTranslationsType,
                fun _ (SingleChoiceTextValue sctv) -> sctv.OptionsTranslations
            )
            Define.Field ("value", StructNullable StringType, fun _ (SingleChoiceTextValue sctv) -> sctv.Value)
            Define.Field (
                "renderType",
                StructNullable CustomFieldRenderTypeType,
                fun _ (SingleChoiceTextValue sctv) -> sctv.RenderType
#warnon 25 // Incomplete pattern match
            )
        ]
    )

Error

Fantomas.Core.ParseException: ParseException
  [{ Severity = Error
     SubCategory = "parse"
     Range = Some (5,0--5,1)
     ErrorNumber = Some 58
     Message =
      "Unexpected syntax or possible incorrect indentation: this token is offside of context started at position (1:1). Try indenting this further.
To continue using non-conforming indentation, pass the '--strict-indentation-' flag to the compiler, or set the language version to F# 7." };
   { Severity = Error
     SubCategory = "parse"
     Range = Some (5,0--5,1)
     ErrorNumber = Some 10
     Message = "Unexpected symbol # in expression. Expected ']' or other token." };
   { Severity = Error
     SubCategory = "parse"
     Range = Some (4,17--4,18)
     ErrorNumber = Some 598
     Message = "Unmatched '['" };
   { Severity = Error
     SubCategory = "parse"
     Range = Some (6,91--6,93)
     ErrorNumber = Some 10
     Message =
      "Unexpected symbol '->' in binding. Expected incomplete structured construct at or before this point or other token." }]
   at Fantomas.Core.CodeFormatterImpl.parse@24.Invoke(Unit unitVar) in /_//src/Fantomas.Core/CodeFormatterImpl.fs:line 29
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 510
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 112

Problem description

When I put #nowarn and #warnon in arbitrary places Fantomas cannot parse the file

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 09/Mar/2026

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