I've been feeling like we could do better in parsing incomplete code. Specifically, I'd love to do what Rust does with incomplete functions, which is add malformed AST nodes and continue parsing to allow the user to get diagnostics on the rest of their code, as opposed to our current approach of showing a single diagnostic at the top of the file explaining the parsing error.
To achieve this, for functions and assignment defs, we would need two things:
This should make implementing return statements easier, as well as making it easier to provide errors/warnings when early returns/crashes are present before other statements in a block.
I'm not actually sure when it's ever a desirable user experience for us to fail parsing in a module entirely instead of locally
Maybe on a malformed header? I don't think so
@Joshua Warner is probably interested in discussing this
Other places would be in empty control flow branches, a.k.a. if an if, else-if, else, or when ... -> had a similarly missing block or non-expression-terminated block
I could also see us wanting to fail early on invalid UTF-8, since that is annoying to have to handle across the entire parsing logic system
Here's maybe a third of the work done in a draft PR: https://github.com/roc-lang/roc/pull/7112
If we like the general approach, I can continue and polish up, add tests, etc.
If not, I'll ignore and continue to implement return sans cleanup
Small bit of context: in reading through our block parsing code, we actually have logic to fail parsing, not typechecking, on the wrong kinds of statements following others. For example, if an expression is seen that doesn't have a ! suffix, then we throw a parsing error for any following statements.
In line with the above goal, I think we should allow parsing any order of statements, and have warnings and errors instead during canonicalization
I like this goal
Last updated: Jun 16 2026 at 16:19 UTC