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

Non needed parentheses are added around lambda call from tuple/members #3082

Open
4 tasks
MangelMaxime opened this issue Apr 22, 2024 · 3 comments
Open
4 tasks

Comments

@MangelMaxime
Copy link

Issue created from fantomas-online

Code

func ("/health", fun a b -> "")

Result

func ("/health", (fun a b -> ""))

Problem description

Please describe here the Fantomas problem you encountered.
Check out our Contribution Guidelines.

Fantomas adds non needed () around the lambda declaration.

Note

This does not happen if you have a multi line lambda

func ("/health", fun a b -> 
    // Force new line
    "")

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 2024-04-16T07:11:28Z - 873d9d7

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 Apr 22, 2024

Hi, thanks for the report. This is one of those things where we add them because it is the safe thing to do to avoid another related problem. I would accept a PR for this if you are interested.

@MangelMaxime
Copy link
Author

This is one of those things where we add them because it is the safe thing to do to avoid another related problem.

That's what I supposed.

I would accept a PR for this if you are interested.

I suppose it should be a small changes, I can give it when I have some time for it. Any pointers, to nudge me in the right direction?

@nojaf
Copy link
Contributor

nojaf commented Apr 23, 2024

Step one would be to add a new test in TupleTests.fs:

[<Test>]
let ``maxime thing`` () =
    formatSourceString
        """
func ("/health", fun a b -> "")
"""
        config
    |> prepend newline
    |> should
        equal
        """
func ("/health", fun a b -> "")
"""

Then take a look in the online tool what func ("/health", fun a b -> "") produces (Oak tab), the tuple is stored in ExprTupleNode.

Next look in CodePrinter.fs where that is being processed:

See let genTupleExpr (node: ExprTupleNode):

| IsLambdaOrIfThenElse e -> sepOpenT +> genExpr e +> sepCloseT

seems to add the parentheses.

Commenting that out will make the test pass and make 31 others fail.

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

No branches or pull requests

2 participants