Skip to content

Long type test with :? gives invalid code #3558

Closed

Description

@nojaf

Issue created from fantomas-online

Code

let x = someLongValueExpressionThatIsLong :? LongTypeNameNumberOneLongTypeNameNumberTwoLongTypeNameNumberThreeLongTypeNameNumberFourLongTypeNameNumberFive

Result

let x =
    someLongValueExpressionThatIsLong
    :? LongTypeNameNumberOneLongTypeNameNumberTwoLongTypeNameNumberThreeLongTypeNameNumberFourLongTypeNameNumberFive

Problem description

Fantomas found this wrong with its result:

  • The result is not valid F#
    • Fantomas cannot parse the code it produced. The diagnostics are about that code.

A type test that does not fit on one line is broken before :?, which then starts its line on the column of the expression. For the offside rule :? is not an infix token, unlike :> and :?>, so the parser reads it as the start of a new expression. The F# compiler rejects the result with FS0010 too (SDK 8.0.426 and 10.0.402).

The same happens when a multiline parenthesized function type follows :?, and when the type test sits inside parentheses (f (someValue :? (A -> B -> ...))). In an if condition the result parses. :, :> and :?> in the same position are fine.

Not a regression: 7.0.6, 8.0.10, main and the 9.0.0-alpha-001 preview all fail.

Found while working on #3554.

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-10-20T12:59:18Z - 79babfa

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.

Activity

  1. added a commit that references this issue on Dec 1, 2026
    2fceb75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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