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

Improve Error Reporting: no expression in computation expression #6717

Open
Tracked by #1103
isaacabraham opened this issue May 13, 2019 · 6 comments
Open
Tracked by #1103

Improve Error Reporting: no expression in computation expression #6717

isaacabraham opened this issue May 13, 2019 · 6 comments
Labels
Area-Diagnostics mistakes and possible improvements to diagnostics Feature Improvement
Milestone

Comments

@isaacabraham
Copy link
Contributor

What

Consider the following code sample:

let foo() =
    async {
        let! result = async { return 0 }
    }

and the associated error message, error FS0010: Unexpected symbol '}' in expression.

Why

The error message doesn't help understand why the error has occurred, nor given any guidance on how to fix it. In addition, the error occurs on the final line (with the }) rather than with the let!. See here for a sample of a real-world issue caused by this.

How

Ending the block with a normal let gives a much better error

let foo() =
    async {
        let result = async { return 0 }
    }

gives The block following this 'let' is unfinished. Every code block is an expression and must have a result. 'let' cannot be the final code element in a block. Consider giving this block an explicit result. (although I think that this message could still be improved...).

How about this for let!s:

'let!' cannot be the final code element in a computation expression block. Consider replacing the use of let! with return! if this is the final expression in the block, or returning some value after this expression, or executing either a do! (or unit-returning) expression after this expression.

@cartermp
Copy link
Contributor

I like the suggestion, but I'd prefer it to be a bit shorter since we're showing too many options:

'let!' cannot be the final code element in a computation expression block. Consider giving this block an explicit result to return.

@cartermp cartermp added this to the Unknown / not bug milestone May 13, 2019
@isaacabraham
Copy link
Contributor Author

@cartermp yep. Maybe keep the return! though as that's a (as far as I can tell) guaranteed and simple fix?

'let!' cannot be the final code element in a computation expression block. Consider replacing the use of let! with return!, or returning another explicit result from this block.

@cartermp
Copy link
Contributor

Sounds good.

@KathleenDollard
Copy link

What do we need to do to move this out of "needs discussion" into "up for grabs"?

@cartermp
Copy link
Contributor

I think this one could be considered up for grabs. The challenge here would be in detecting the pattern rather than emitting the parse error.

@baronfel
Copy link
Member

Note to potential implementors - consider using this fantomas tools link to help you find the correct parse tree shapes on which to give the error.

@dsyme dsyme added Area-Diagnostics mistakes and possible improvements to diagnostics and removed Area-Compiler labels Mar 31, 2022
@vzarytovskii vzarytovskii moved this to Not Planned in F# Compiler and Tooling Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Diagnostics mistakes and possible improvements to diagnostics Feature Improvement
Projects
Status: New
Development

No branches or pull requests

5 participants