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

Removes type annotation without brackets #2942

Closed
1 of 4 tasks
artemiipatov opened this issue Aug 1, 2023 · 1 comment · Fixed by #3093
Closed
1 of 4 tasks

Removes type annotation without brackets #2942

artemiipatov opened this issue Aug 1, 2023 · 1 comment · Fixed by #3093

Comments

@artemiipatov
Copy link

Issue created from fantomas-online

Code

let clReducedValues, clFirstActualKeys, clSecondActualKeys: ClArray<'a> * ClArray<int> * ClArray<int> =
    reduce processor DeviceOnly resultLength clOffsets clFirstKeys clSecondKeys clValues

Result

let clReducedValues, clFirstActualKeys, clSecondActualKeys =
    reduce processor DeviceOnly resultLength clOffsets clFirstKeys clSecondKeys clValues

Problem description

Fantomas removes type annotation without brackets. But when brackets are placed around names, annotations are not removed.

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 1/1/1990

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.

@nojaf
Copy link
Contributor

nojaf commented Aug 16, 2023

Hello, thank you for your interest in this project!
Tuple bindings are covered a bit differently due to historical reasons. Which is why the return type is missing.

I believe the problem is centered around:

let genDestructedTuples =
expressionFitsOnRestOfLine (genPat pat) (sepOpenT +> genPat pat +> sepCloseT)

There we could do something like:

let genDestructedTuples =
    expressionFitsOnRestOfLine (genPat pat) (sepOpenT +> genPat pat +> sepCloseT)
    +> optSingle
        (fun (rt: BindingReturnInfoNode) ->
            genSingleTextNode rt.Colon
            +> sepSpace
            +> atCurrentColumnIndent (genType rt.Type))
        b.ReturnType

to print the return type when it is present.

I'm not sure how well this exact fix would play when the tuple is multiline.
Something like

let a, //
    b, //
    c 
         : int * int * int = 1,2,3

Might be a corner case.

Are you interested in submitting a PR for this one?

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