feat: improve parser error recovery for function parameters

This commit is contained in:
Aleksey Kladov
2021-07-17 22:41:04 +03:00
parent a2f83c956e
commit 15f11dce4a
10 changed files with 106 additions and 21 deletions

View File

@@ -21,8 +21,11 @@ fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
// test_err static_underscore
// static _: i32 = 5;
types::ascription(p);
if p.at(T![:]) {
types::ascription(p);
} else {
p.error("missing type for `const` or `static`")
}
if p.eat(T![=]) {
expressions::expr(p);
}

View File

@@ -106,7 +106,13 @@ fn param(p: &mut Parser, m: Marker, flavor: Flavor) -> Variadic {
if variadic_param(p) {
res = Variadic(true)
} else {
types::ascription(p);
if p.at(T![:]) {
types::ascription(p)
} else {
// test_err missing_fn_param_type
// fn f(x y: i32, z, t: i32) {}
p.error("missing type for function parameter")
}
}
}
// test value_parameters_no_patterns
@@ -126,7 +132,11 @@ fn param(p: &mut Parser, m: Marker, flavor: Flavor) -> Variadic {
if variadic_param(p) {
res = Variadic(true)
} else {
types::ascription(p);
if p.at(T![:]) {
types::ascription(p)
} else {
p.error("missing type for function parameter")
}
}
} else {
types::type_(p);

View File

@@ -67,7 +67,11 @@ fn const_param(p: &mut Parser, m: Marker) {
assert!(p.at(T![const]));
p.bump(T![const]);
name(p);
types::ascription(p);
if p.at(T![:]) {
types::ascription(p);
} else {
p.error("missing type for const parameter");
}
// test const_param_defaults
// struct A<const N: i32 = -1>;

View File

@@ -55,7 +55,8 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) {
}
pub(super) fn ascription(p: &mut Parser) {
p.expect(T![:]);
assert!(p.at(T![:]));
p.bump(T![:]);
type_(p)
}