Skip to content

Insertion of a newline changes precedence of the ||> operator #2866

@ljb

Description

@ljb

Issue created from fantomas-online

Code

module Test

let createTuple (a: string) (b: string) = a, b

let value =
    match "string" with
    | "value" -> "1", "2"
    | _ -> "111111111111111111111111111111111111111111111111111111111111111111111", "22222222222222222222222222222222222"
    ||> createTuple

Result

module Test

let createTuple (a: string) (b: string) = a, b

let value =
    match "string" with
    | "value" -> "1", "2"
    | _ ->
        "111111111111111111111111111111111111111111111111111111111111111111111",
        "22222222222222222222222222222222222" ||> createTuple

Problem description

Running version 6.0.1 of Fantomas locally results in a slighly different formating compared to the online version:

module Test

let createTuple (a: string) (b: string) = a, b

let value =
    match "string" with
    | "value" -> "1", "2"
    | _ ->
        "111111111111111111111111111111111111111111111111111111111111111111111", "22222222222222222222222222222222222"
    ||> createTuple

Both the code generated by Fantomas online and localy results in the same compilation error. Running dotnet build with the .NET SDK 7.0.203 will give the following error:

C:\repos\test\test.fs(10,9): error FS0001: This expression was expected to have type↔    ''a * 'b'    ↔but here has type↔    'string' [C:\repos\test\test.fsproj]
C:\repos\test\test.fs(10,51): error FS0001: The type 'string' does not match the type 'string * string' [C:\repos\test\test.fsproj]

The problem is that the call to ||> createTuple will be run on the entire match-expression when there isn't a newline. When there is a newline, it will only be run against the line above.

Adding parenthesis around the entire match expression before calling createTuple is a workaround.

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.

Options

Fantomas main branch at 04/26/2023

Default Fantomas configuration

Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?

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