Improve error handling for top-level let statements

This commit addresses the issue of excessive and unrelated errors
generated by top-level `let` statements. Now, only a single error is
produced, indicating that `let` statements are invalid at the top level.
This commit is contained in:
Yutaro Ohno 2023-11-25 15:01:51 +09:00
parent c9d189d137
commit e076192dd8
5 changed files with 86 additions and 44 deletions

View file

@ -376,6 +376,16 @@ fn error_block(p: &mut Parser<'_>, message: &str) {
m.complete(p, ERROR);
}
// test_err top_level_let
// let ref foo: fn() = 1 + 3;
fn error_let_stmt(p: &mut Parser<'_>, message: &str) {
assert!(p.at(T![let]));
let m = p.start();
p.error(message);
expressions::let_stmt(p, expressions::Semicolon::Optional);
m.complete(p, ERROR);
}
/// The `parser` passed this is required to at least consume one token if it returns `true`.
/// If the `parser` returns false, parsing will stop.
fn delimited(