Recover from leading comma in tuple pat and expr

This commit is contained in:
Lukas Wirth 2023-06-01 08:40:50 +02:00
parent 42450d2511
commit 7d1bf7023d
7 changed files with 89 additions and 4 deletions

View file

@ -184,6 +184,16 @@ fn tuple_expr(p: &mut Parser<'_>) -> CompletedMarker {
let mut saw_comma = false;
let mut saw_expr = false;
// test_err tuple_expr_leading_comma
// fn foo() {
// (,);
// }
if p.eat(T![,]) {
p.error("expected expression");
saw_comma = true;
}
while !p.at(EOF) && !p.at(T![')']) {
saw_expr = true;

View file

@ -413,6 +413,16 @@ fn tuple_pat(p: &mut Parser<'_>) -> CompletedMarker {
let mut has_comma = false;
let mut has_pat = false;
let mut has_rest = false;
// test_err tuple_pat_leading_comma
// fn foo() {
// let (,);
// }
if p.eat(T![,]) {
p.error("expected pattern");
has_comma = true;
}
while !p.at(EOF) && !p.at(T![')']) {
has_pat = true;
if !p.at_ts(PAT_TOP_FIRST) {