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

if/then/else indented too far #1054

Closed
1 of 3 tasks
nojaf opened this issue Aug 28, 2020 · 0 comments · Fixed by #1058
Closed
1 of 3 tasks

if/then/else indented too far #1054

nojaf opened this issue Aug 28, 2020 · 0 comments · Fixed by #1058

Comments

@nojaf
Copy link
Contributor

nojaf commented Aug 28, 2020

Issue created from fantomas-online

Code

let merge a b =
    let aChunks = splitWhenHash a
    let bChunks = splitWhenHash b
    
    if List.length aChunks <> List.length bChunks then
        Dbg.print (aChunks, bChunks)
        failwithf """Fantomas is trying to format the input multiple times due to the detect of multiple defines.
There is a problem with merging all the code back togheter. Please raise an issue at https://github.com/fsprojects/fantomas/issues."""
    
    List.zip aChunks bChunks
    |> List.map (fun (a', b') ->
        let la = lengthWithoutSpaces a'
        let lb = lengthWithoutSpaces b'
        if la <> lb then 
            if la > lb then a' else b'
        else
            if String.length a' < String.length b' then a' else b' 
    )
    
    |> String.concat Environment.NewLine

Error

Fantomas was able to format the code but the result appears to be invalid F# code.
Please open an issue.

Formatted result:

let merge a b =
    let aChunks = splitWhenHash a
    let bChunks = splitWhenHash b

                                 if List.length aChunks <> List.length bChunks then
                                     Dbg.print (aChunks, bChunks)
                                     failwithf """Fantomas is trying to format the input multiple times due to the detect of multiple defines.
There is a problem with merging all the code back togheter. Please raise an issue at https://github.com/fsprojects/fantomas/issues."""

                                 List.zip aChunks bChunks
                                 |> List.map (fun (a', b') ->
                                     let la = lengthWithoutSpaces a'
                                     let lb = lengthWithoutSpaces b'
                                     if la <> lb then if la > lb then a' else b'
                                     else if String.length a' < String.length b' then a'
                                     else b')

                                 |> String.concat Environment.NewLine

Problem description

This appears to be a trivia bug, strict mode works.

Extra information

  • The formatted result breaks by code.
  • The formatted result gives compiler warnings.
  • I or my company would be willing to help fix this.

Options

Fantomas Master at 8/28/2020

Default Fantomas configuration

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

Successfully merging a pull request may close this issue.

1 participant