mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Unify more invalid declaration recovery. (#3942)
When we expect a semicolon, we should be able to provide more standard
recovery.
Note this affects a test of `base`, but it looks like a partial
improvement (the prior line was moving too far). Still, it looks like
recovery isn't handling `{}` quite right. I'm not trying to address that
here though -- leaving a TODO.
This commit is contained in:
@@ -13,22 +13,10 @@ static auto HandleDeclOrDefinition(Context& context, NodeKind decl_kind,
|
||||
State definition_finish_state) -> void {
|
||||
auto state = context.PopState();
|
||||
|
||||
if (state.has_error) {
|
||||
context.RecoverFromDeclError(state, decl_kind,
|
||||
/*skip_past_likely_end=*/true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto semi = context.ConsumeIf(Lex::TokenKind::Semi)) {
|
||||
context.AddNode(decl_kind, *semi, state.subtree_start, state.has_error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context.PositionIs(Lex::TokenKind::OpenCurlyBrace)) {
|
||||
context.DiagnoseExpectedDeclSemiOrDefinition(
|
||||
context.tokens().GetKind(state.token));
|
||||
context.RecoverFromDeclError(state, decl_kind,
|
||||
/*skip_past_likely_end=*/true);
|
||||
if (state.has_error || !context.PositionIs(Lex::TokenKind::OpenCurlyBrace)) {
|
||||
context.AddNodeExpectingDeclSemi(state, decl_kind,
|
||||
context.tokens().GetKind(state.token),
|
||||
/*is_def_allowed=*/true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user