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:
MK4070
2026-03-04 14:57:48 +00:00
committed by GitHub
co-authored by Dana Jansens Carbon Infra Bot
parent 15680ba101
commit 1c7a4030ab
2 changed files with 63 additions and 6 deletions
+8 -1
View File
@@ -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);
}
}