Avoid speculatively pushing a pattern block in impl handling (#4943)

To do this, we restructure the parse tree to make `forall` a leaf node
that comes before the parameter list.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
Geoff Romer
2025-02-12 23:21:57 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent 95f2140a04
commit f502e8d6ff
7 changed files with 67 additions and 70 deletions
+1 -2
View File
@@ -27,7 +27,7 @@ auto HandleImplAfterIntroducer(Context& context) -> void {
if (context.PositionIs(Lex::TokenKind::Forall)) {
// forall [<implicit parameter list>] ...
context.PushState(State::ImplAfterForall);
context.ConsumeAndDiscard();
context.AddLeafNode(NodeKind::Forall, context.Consume());
if (context.PositionIs(Lex::TokenKind::OpenSquareBracket)) {
context.PushState(State::PatternListAsImplicit);
} else {
@@ -53,7 +53,6 @@ auto HandleImplAfterForall(Context& context) -> void {
if (state.has_error) {
context.ReturnErrorOnState();
}
context.AddNode(NodeKind::ImplForall, state.token, state.has_error);
// One of:
// as <expression> ...
// <expression> as <expression>...