mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Avoid consuming a token after an invalid match_first opening (#7538)
If the `match_first` is not followed by `{` avoid consuming whatever
comes after it. Recover by leaving whatever comes next alone. It could
even be the `FileEnd` token, and then we would crash when we read off
the end of the token stream looking for `FileEnd`.
This commit is contained in:
@@ -26,7 +26,12 @@ auto HandleMatchFirst(Context& context) -> void {
|
||||
|
||||
auto HandleMatchFirstFinish(Context& context) -> void {
|
||||
auto state = context.PopState();
|
||||
context.AddNode(NodeKind::MatchFirst, context.Consume(), state.has_error);
|
||||
if (auto closing_token = context.ConsumeIf(Lex::TokenKind::CloseCurlyBrace)) {
|
||||
context.AddNode(NodeKind::MatchFirst, *closing_token, state.has_error);
|
||||
} else {
|
||||
// Recover from error by just moving on.
|
||||
context.AddNode(NodeKind::MatchFirst, state.token, state.has_error);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Carbon::Parse
|
||||
|
||||
Reference in New Issue
Block a user