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

begin/end are replaced with parens #2368

Closed
3 tasks
auduchinok opened this issue Jul 16, 2022 · 3 comments · Fixed by #2950
Closed
3 tasks

begin/end are replaced with parens #2368

auduchinok opened this issue Jul 16, 2022 · 3 comments · Fixed by #2950

Comments

@auduchinok
Copy link
Contributor

Issue created from fantomas-online

Code

do
    begin 1 end

Result

do (1)

Problem description

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

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.

Options

Fantomas master branch at 2022-07-15T14:30:45Z - 87cd212

Default Fantomas configuration

Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?

@auduchinok auduchinok changed the title begin/end are replaced with parens begin/end are replaced with parens Jul 16, 2022
@nojaf
Copy link
Contributor

nojaf commented Jul 18, 2022

The AST is identical to do (1), so without any additional trivia in the syntax tree, we cannot reconstruct the original result.

@auduchinok
Copy link
Contributor Author

The AST is identical to do (1)

It looks like that indeed, but there's still a small difference. The only case where SynExpr.Paren is produced for something not starting with ( is beginEndExpr, and as a workaround we could check leftParenRange length to see if it's longer than a paren. I agree, though, that it'd be better to have it properly shown in the tree in the long-term. 🙂

@auduchinok
Copy link
Contributor Author

I've seen begin/end expressions used for scoping (and using disposables), so here's a bit less minimal case to show the change:

do
    let a = 1
    begin
        use b = f ()
        ()
    end
    let c = 2
    ()

Which gets formatted to:

do
    let a = 1

    (use b = f ()
     ())

    let c = 2
    ()

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