mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 14:01:06 +01:00
Improve error recovery in binding patterns (#4309)
Co-authored-by: Richard Smith <richard@metafoo.co.uk> Co-authored-by: Josh L <josh11b@users.noreply.github.com>
This commit is contained in:
co-authored by
Richard Smith
Josh L
parent
a8d4f068e3
commit
88f3b3470f
@@ -26,14 +26,12 @@ auto HandleBindingPattern(Context& context) -> void {
|
||||
|
||||
// Handle an invalid pattern introducer for parameters and variables.
|
||||
auto on_error = [&]() {
|
||||
CARBON_DIAGNOSTIC(ExpectedBindingPattern, Error,
|
||||
"Expected binding pattern.");
|
||||
context.emitter().Emit(*context.position(), ExpectedBindingPattern);
|
||||
// Add a placeholder for the type.
|
||||
context.AddLeafNode(NodeKind::InvalidParse, *context.position(),
|
||||
/*has_error=*/true);
|
||||
state.has_error = true;
|
||||
context.PushState(state, State::BindingPatternFinishAsRegular);
|
||||
if (!state.has_error) {
|
||||
CARBON_DIAGNOSTIC(ExpectedBindingPattern, Error,
|
||||
"Expected binding pattern.");
|
||||
context.emitter().Emit(*context.position(), ExpectedBindingPattern);
|
||||
state.has_error = true;
|
||||
}
|
||||
};
|
||||
|
||||
// The first item should be an identifier or `self`.
|
||||
@@ -53,7 +51,6 @@ auto HandleBindingPattern(Context& context) -> void {
|
||||
context.AddLeafNode(NodeKind::IdentifierName, *context.position(),
|
||||
/*has_error=*/true);
|
||||
on_error();
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto kind = context.PositionKind();
|
||||
@@ -67,7 +64,10 @@ auto HandleBindingPattern(Context& context) -> void {
|
||||
context.PushStateForExpr(PrecedenceGroup::ForType());
|
||||
} else {
|
||||
on_error();
|
||||
return;
|
||||
// Add a placeholder for the type.
|
||||
context.AddLeafNode(NodeKind::InvalidParse, *context.position(),
|
||||
/*has_error=*/true);
|
||||
context.PushState(state, State::BindingPatternFinishAsRegular);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user