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

tuple with match formats to invalid code #1269

Closed
2 of 3 tasks
ThisFunctionalTom opened this issue Nov 24, 2020 · 4 comments · Fixed by #1270
Closed
2 of 3 tasks

tuple with match formats to invalid code #1269

ThisFunctionalTom opened this issue Nov 24, 2020 · 4 comments · Fixed by #1270

Comments

@ThisFunctionalTom
Copy link
Contributor

Issue created from fantomas-online

Code

let a = "Hello"
match a with
    | "first" -> 1
    | "second" -> 2
    , []

Result

let a = "Hello"

match a with
| "first" -> 1
| "second" -> 2,
[]

Problem description

When formatting a tuple with pattern match as first element fantomas puts comma in the wrong place and generates not compilable code.

Expected formatting:

let a = "Hello"

match a with
| "first" -> 1
| "second" -> 2
,[]

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 4.2.0

Default Fantomas configuration

@nojaf
Copy link
Contributor

nojaf commented Nov 24, 2020

Hello Tom,

Thank you for reporting this issue. It appears that Fantomas joins every synExpr of a tuple with a comma and a new line (if the whole expression is multiline).

So in pseudo code:

let myTuple = a, b

If a, b is multiline it will go like

let myTuple =
    a,
    b

See genTuple. In the case of SynExpr.Match, this leads to different code that what you originally had.

Would you be interested in submitting a pull request?

@ThisFunctionalTom
Copy link
Contributor Author

I'll give it a try.

@ThisFunctionalTom
Copy link
Contributor Author

Hi Florian,

thank you so much for explaining the issue and pointing to the right place.

I wrote some unit tests and fixed this issue, or at least I hope I fixed it 😅 .

One thing I am not sure if it's important.

If I have a long tuple and the match is the last element in it should it also be formatted with commas at the beginning of the line?

Here two examples.

This

match "Hello" with 
| "first" -> 1 
| "second" -> 2 
| _ -> 3
, 1
, "Hello"  

must be formatted like it is, I think, because of the semantics.

But this

1
, "Hello"
, match "Hello" with 
  | "first" -> 1 
  | "second" -> 2 
  | _ -> 3

can be formatted like this

1, 
"Hello", 
match "Hello" with 
| "first" -> 1 
| "second" -> 2 
| _ -> 3

with my current implementation it will be formatted with commas at the beginning of the line.
I am not sure if it is OK. What do you think?

Also, I think that maybe it is not important. One should not write code like this 😁

image

@c-rindi
Copy link
Contributor

c-rindi commented Dec 14, 2020

@ThisFunctionalTom Thanks for submitting the PR (and humour)!

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.

3 participants