Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect code when function type parameter would break over line #1637

Closed
Smaug123 opened this issue Apr 12, 2021 · 1 comment · Fixed by #1639
Closed

Incorrect code when function type parameter would break over line #1637

Smaug123 opened this issue Apr 12, 2021 · 1 comment · Fixed by #1639

Comments

@Smaug123
Copy link
Contributor

Smaug123 commented Apr 12, 2021

The code is too long to use the online tool, sorry.

Input:

[<NoEquality ; NoComparison>]
type Foo<'context, 'a> =
    | Apply of ApplyCrate<'context, 'a>

and [<CustomEquality ; NoComparison>] Bar<'context, 'a> =
    internal {
        Hash : int
        Foo : Foo<'a, 'b>
    }
    member this.InnerEquals<'innerContextLongLongLong, 'd, 'e> (a : Foo<'innerContextLongLongLong, 'd>) (b : Foo<'innerContext, 'd>) (cont : bool -> 'e) : 'e =
        if a.Hash <> b.Hash then cont false
        else
            match a.Foo, b.Foo with
            | Foo.Apply a, Foo.Apply b ->
                a.Apply { new ApplyEval<_, _, _> with
                    member __.Eval<'bb> (a : Foo<'innerContextLongLongLong, 'bb -> 'b> * Foo<'innerContextLongLongLong, 'bb>) =
                        let (af, av) = a
                        b.Apply { new ApplyEval<_, _, _> with
                            member __.Eval<'cb> (b : Foo<'innerContextLongLongLong, 'cb -> 'b> * Foo<'innerContextLongLongLong, 'bc>) =
                                let (bf, bv) = b
                                if typeof<'bb> = typeof<'cb> then
                                    let bv = unbox<Foo<'innerContextLongLongLong, 'bb>> bv
                                    this.InnerEquals av bv (fun inner ->
                                        if inner then
                                            let bv = unbox<Foo<'innerContextLongLongLong, 'bb -> 'b>> bf
                                            this.InnerEquals af bf cont
                                        else cont false
                                    )
                                else cont false
                        }
                }

Output:

[<NoEquality ; NoComparison>]
type Foo<'context, 'a> = Apply of ApplyCrate<'context, 'a>

and [<CustomEquality ; NoComparison>] Bar<'context, 'a> =
    internal
        {
            Hash : int
            Foo : Foo<'a, 'b>
        }
    member this.InnerEquals<'innerContextLongLongLong, 'd, 'e>
        (a : Foo<'innerContextLongLongLong, 'd>)
        (b : Foo<'innerContext, 'd>)
        (cont : bool -> 'e)
        : 'e
        =
        if a.Hash <> b.Hash then
            cont false
        else
            match a.Foo, b.Foo with
            | Foo.Apply a, Foo.Apply b ->
                a.Apply
                    { new ApplyEval<_, _, _> with
                        member __.Eval<'bb>
                            (a : Foo<'innerContextLongLongLong, 'bb -> 'b> * Foo<'innerContextLongLongLong, 'bb>)
                            =
                            let (af, av) = a

                            b.Apply
                                { new ApplyEval<_, _, _> with
                                    member __.Eval<'cb>
                                        (b : Foo<'innerContextLongLongLong, 'cb -> 'b> * Foo<'innerContextLongLongLong, 'bc>)
                                        =
                                        let (bf, bv) = b

                                        if typeof<'bb> = typeof<'cb> then
                                            let bv =
                                                unbox<Foo<'innerContextLongLongLong, 'bb>> bv

                                            this.InnerEquals
                                                av
                                                bv
                                                (fun inner ->
                                                    if inner then
                                                        let bv =
                                                            unbox<Foo<'innerContextLongLongLong, 'bb ->
                                                                'b>>
                                                                bf

                                                        this.InnerEquals af bf cont
                                                    else
                                                        cont false
                                                )
                                        else
                                            cont false
                                }
                    }

The formatted code has two parse errors, I believe due to the unbox call being split over two lines at a bad place:

    (46,67) (46, 66)Error10parse

    Incomplete structured construct at or before this point in type arguments. Expected ',' or other token.
    (46,67) (46, 66)Error1241parse

    Expected type argument or static argument

Settings:

[*.fs]
max_line_length=100
fsharp_space_before_uppercase_invocation=true
fsharp_space_before_class_constructor=true
fsharp_space_before_member=true
fsharp_space_before_colon=true
fsharp_space_before_semicolon=true
fsharp_multiline_block_brackets_on_same_column=true
fsharp_keep_if_then_in_same_line=true
fsharp_align_function_signature_to_indentation=true
fsharp_alternative_long_member_definitions=true
fsharp_multi_line_lambda_closing_newline=true
fsharp_keep_indent_in_branch=true

I think this is a recent issue; I don't remember this file formatting incorrectly in the past.

Version: Master at 04/11/2021 18:54:45 - f992dd7

@nojaf
Copy link
Contributor

nojaf commented Apr 12, 2021

Thanks for reporting, this is related to a recent change.
Smaller sample

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants