Skip to content

Type annotation ends up with many spaces, adjusted for the previous expression's length #3179

@jp-fournier-dev

Description

@jp-fournier-dev

While applying Fantomas to our code base, I fell upon this issue where the type annotation will be filled with spaces to match up with the previous expressions length. In the example, if you remove one call of anotherOne, the formatting will adjust the length of the spacing that will be added in consequence.

Seems like we might be setting the position of the closing > in accordance to the wrong expression

There is an easy workaround. This will not materialize itself if the faulty expression is directly on the next line from the first expression, ie. :

module SomeModule =

    let someFunctionCall() = "hello"

    let anotherOne s = s 
    
    let alsoAnotherOne s = s |> ignore

    type SomeType with
        member this.Reraise() =
            (someFunctionCall()) |> anotherOne |> anotherOne |> alsoAnotherOne
            Unchecked.defaultof<_>

Issue created from fantomas-online

Code

module SomeModule =

    let someFunctionCall() = "hello"

    let anotherOne s = s 
    
    let alsoAnotherOne s = s |> ignore

    type SomeType with
        member this.Reraise() =
            (someFunctionCall()) |> anotherOne |> anotherOne |> alsoAnotherOne

            Unchecked.defaultof<_>

Result

module SomeModule =

    let someFunctionCall () = "hello"

    let anotherOne s = s

    let alsoAnotherOne s = s |> ignore

    type SomeType with
        member this.Reraise() =
            (someFunctionCall ()) |> anotherOne |> anotherOne |> alsoAnotherOne

            Unchecked.defaultof<_                                               >

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

Options

Fantomas main branch at 2025-08-06T12:58:25Z - cbee488

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