From 1addf1005492deca0f34d3071f60f3429cd97b6c Mon Sep 17 00:00:00 2001 From: josh11b Date: Mon, 11 Dec 2023 09:22:17 -0800 Subject: [PATCH] Move add invalid node. Follow up to #3473. (#3491) I think this matches expectations about how the parse code should be structured better. --- toolchain/parse/handle_impl.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/toolchain/parse/handle_impl.cpp b/toolchain/parse/handle_impl.cpp index a67df0d6a5a5..12d8fb166e38 100644 --- a/toolchain/parse/handle_impl.cpp +++ b/toolchain/parse/handle_impl.cpp @@ -34,6 +34,11 @@ auto HandleImplAfterIntroducer(Carbon::Parse::Context& context) -> void { "Expected `[` after `forall` in `impl` declaration."); context.emitter().Emit(*context.position(), ImplExpectedAfterForall); context.ReturnErrorOnState(); + // If we aren't producing a node from the PatternListAsImplicit state, + // we still need to create a node to be the child of the `ImplForall` + // token created in the `ImplAfterForall` state. + context.AddLeafNode(NodeKind::InvalidParse, *context.position(), + /*has_error=*/true); } } else { // One of: @@ -46,8 +51,6 @@ auto HandleImplAfterIntroducer(Carbon::Parse::Context& context) -> void { auto HandleImplAfterForall(Carbon::Parse::Context& context) -> void { auto state = context.PopState(); if (state.has_error) { - context.AddLeafNode(NodeKind::InvalidParse, *context.position(), - /*has_error=*/true); context.ReturnErrorOnState(); } context.AddNode(NodeKind::ImplForall, state.token, state.subtree_start,