mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
fix malformed parse tree for invalid let struct pattern (#7782)
Fixes the malformed parse tree produced for an invalid let struct
pattern containing a single identifier (e.g., `let {s};`).
As pointed out by @DavidLoftus, the parser should produce a parse tree
similar to that of `let {ref s};`, since both are missing a binding
power operator `:`, and both do not have a `.` preceding the identifier
(i.e., `state.in_field_shorthand_pattern == true`).
This means that the parser can produce an the `InvalidParse` node just
as it does for `let {ref s};`.
Closes #7674
This commit is contained in:
@@ -47,9 +47,10 @@ auto HandlePattern(Context& context) -> void {
|
||||
state.binding_context, state.ambient_precedence);
|
||||
break;
|
||||
default:
|
||||
if (context.PositionKind().is_word() &&
|
||||
context.PositionKind(Lookahead::NextToken)
|
||||
.is_binding_pattern_operator()) {
|
||||
if ((context.PositionKind().is_word() &&
|
||||
context.PositionKind(Lookahead::NextToken)
|
||||
.is_binding_pattern_operator()) ||
|
||||
state.in_field_shorthand_pattern) {
|
||||
context.PushStateForPattern(
|
||||
StateKind::BindingPattern, state.in_var_pattern,
|
||||
state.in_unused_pattern, state.in_field_shorthand_pattern,
|
||||
|
||||
Reference in New Issue
Block a user