Skip to content

Multiline tuple in the middle of a function type gives invalid code #3556

Closed

Description

@nojaf

Issue created from fantomas-online

Code

type T = a -> int * LongTypeNameNumberOneLongTypeNameNumberTwoLongTypeNameNumberThreeLongTypeNameNumberFourLongTypeNameNumberFive -> unit

Result

type T =
    a
        -> int *
        LongTypeNameNumberOneLongTypeNameNumberTwoLongTypeNameNumberThreeLongTypeNameNumberFourLongTypeNameNumberFive
        -> unit

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.

When a tuple is a middle operand of a function type and does not fit on its line, Fantomas breaks it after * and puts the next item in the column of the outer -> lines. The -> unit that follows is then read as part of the tuple and does not parse.

  • Fails: a tuple as a middle operand, in a type abbreviation or in a parameter annotation (let f (x: a -> int * X -> unit) = ()).
  • Passes: the tuple as the first operand (int * X -> unit stays on one line), or as the last one (a -> int * X).
  • A parenthesized function type as the second tuple item, as in string -> int * (A -> B -> C) -> unit, fails the same way.

Fails on 7.0.6, 8.0.10, main, and the 9.0.0-alpha-001 preview.

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
    0982228
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