Why this fires
The parser was expecting a specific token at this position — typically }, ), ;, an identifier, or the next part of a syntactic construct — but found something different (often the start of the following statement).
fn area(width: float, height: float -> float {
// ^ error: expected `,` or `)`
return width * height
}
Missing punctuation on an earlier line is the usual culprit; the parser keeps going until it can't reconcile what it sees, and the carat ends up after the actual mistake.
Fix it
1. Re-read the line above
Look at the line before the carat first. Most P0002 errors are caused by a missing comma, semicolon, or closing brace one line above.
2. Match braces and parens
Editor support: most editors highlight the matching } / ) when the caret is on one of the pair. Walk back from the diagnostic to find the open bracket that has no partner.
3. Use the formatter
zolo fmt will not parse a broken file, but it will refuse with a message pointing at the same span. When the file does parse, the formatter rewrites it consistently — which makes the next P0002 easier to read.
Common patterns
| Mistake | Fix |
|---|---|
Missing , between parameters |
Add the comma |
Missing } on a previous block |
Close the block |
Stray ; at the end of an expression |
Remove it (Zolo uses newlines) |
Mixed => / -> in match vs. function |
=> in match, -> for return |
See also
P0003— an unexpected token rather than a missing expected one.