Improve Error Reporting: "inner" expressions inside computations expressions #2739
Labels
Area-Diagnostics
mistakes and possible improvements to diagnostics
Feature Improvement
Theme-Simple-F#
A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.
Milestone
@dsyme - as per your email w/ Dave Thomas...
What
If you create a computation expression that has a nested expression inside it bound to a value, you need to explicitly create a "child" computation expression for the nested expression.
You can fix it either by explicitly wrapping the nested
match
expression branches in their own CEs: -or the entire child expression
Why
The error message is misleading: as far are the developer is concerned, they are in an
async
CE; it's not clear at all that by creating a nested expression within the parent CE, the user has "left" the CE.How
If it's possible for the compiler to detect this, the error message should be clearer e.g.
Code within a nested expressions (e.g. "if" or "match") exists outside of any parent computation expression. In order to perform actions such as let! or do!, the nested expression must be wrapped within its own computation expression.
It would also be useful (and this is something that we should consider doing with many other error messages) to give a "before / after" example (as I've done here) either directly inside the compiler error message, or somehow linking to one.
Alternatively, depending on the complexity and whether this could be determined up front, the compiler could do this "nested wrapping" for us.
The text was updated successfully, but these errors were encountered: