mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Parse invalid lambdas without crashing (#6826)
Fixes a compiler crash that occurs when a malformed lambda is provided as an operand to an operator that strictly expects an expression Changes: - Emits an `InvalidParse` dummy node at the current position to act as a placeholder for the missing body - Changed state transitions so that `LambdaIntroducer` gets properly wrapped into a `Lambda` node Closes #6823 --------- Co-authored-by: Dana Jansens <danakj@orodu.net> Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
This commit is contained in:
co-authored by
Dana Jansens
Carbon Infra Bot
parent
15680ba101
commit
1c7a4030ab
@@ -87,8 +87,15 @@ auto HandleLambdaBody(Context& context) -> void {
|
||||
"expected `=>` or `{{` after return type");
|
||||
context.emitter().Emit(*context.position(),
|
||||
ExpectedLambdaBodyAfterReturnType);
|
||||
|
||||
// Add a dummy node for the missing body without consuming the current
|
||||
// token.
|
||||
context.AddLeafNode(NodeKind::InvalidParse, *context.position(),
|
||||
/*has_error=*/true);
|
||||
|
||||
state.has_error = true;
|
||||
context.ReturnErrorOnState();
|
||||
// Bundle all nodes into a complete lambda node.
|
||||
context.PushState(state, StateKind::LambdaBodyFinish);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user