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

(Empty/NoEmpty)-bodied named computation expression produces inconsistent formatting #3140

Open
3 of 4 tasks
edgarfgp opened this issue Dec 9, 2024 · 6 comments
Open
3 of 4 tasks

Comments

@edgarfgp
Copy link
Contributor

edgarfgp commented Dec 9, 2024

Issue created from fantomas-online

When formatting Empty-bodied named computation expression causes:

error FS0003: This value is not a function and cannot be applied.

Code

A() {} // Empty-bodied

B() { 0 }

Result

A () { } // Empty-bodied

B() { 0 }

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.
  • I would like a release if this problem is solved.

Options

Fantomas main branch at 2024-10-29T08:28:00Z - b7dca79

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 Dec 9, 2024

Thank for reporting this, it is somewhat interesting that we are not making the correct Oak node I see. I'll take a look.

@nojaf
Copy link
Contributor

nojaf commented Dec 9, 2024

The wrong AST is produced in this case:

                    SynModuleDecl.Expr(
                        expr =
                            SynExpr.App(
                                flag = ExprAtomicFlag.NonAtomic,
                                isInfix = false,
                                funcExpr =
                                    SynExpr.App(
                                        flag = ExprAtomicFlag.Atomic,
                                        isInfix = false,
                                        funcExpr = SynExpr.Ident(Ident("A", R("(1,0--1,1)"))),
                                        argExpr = SynExpr.Const(constant = SynConst.Unit, range = R("(1,1--1,3)")),
                                        range = R("(1,0--1,3)")
                                    ),
                                argExpr = SynExpr.Record(baseInfo = None, copyInfo = None, recordFields = [], range = R("(1,4--1,6)")),
                                range = R("(1,0--1,6)")
                            ),
                        range = R("(1,0--1,6)")
                    )

The SynExpr.ComputationExpr is not there, so you'd need to check is this is a parser bug or by design?

@edgarfgp
Copy link
Contributor Author

edgarfgp commented Dec 9, 2024

Thanks Florian. Will look into it.

@edgarfgp
Copy link
Contributor Author

@nojaf Looks like this is by design unfortunately. But in F# 9 the compiler re-writes the Untyped AST from SynExpr.Record to SynExpr.ComputationExpr adding an a dummySynExpr.Const (SynConst.Unit, range0))forA() {}`

See: https://github.com/edgarfgp/fsharp/blame/935b796dc841b6346f655421bb791c1764ab1570/src/Compiler/Checking/Expressions/CheckExpressions.fs#L8546

Do you think Fantomas can also do the same ?

@nojaf
Copy link
Contributor

nojaf commented Dec 10, 2024

I see, yeah, we could cook something similar in Fantomas.

@nojaf
Copy link
Contributor

nojaf commented Dec 12, 2024

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