diff --git a/spec/runtime/stack_spec.cc b/spec/runtime/stack_spec.cc index 80826312..b418cc16 100644 --- a/spec/runtime/stack_spec.cc +++ b/spec/runtime/stack_spec.cc @@ -463,6 +463,29 @@ describe("Stack", [&]() { free_slice_array(&pop.slices); }); + it("skips entries whose trees are extra", [&]() { + ts_stack_push(stack, 0, trees[1], true, stateB); + + trees[2]->extra = true; + trees[3]->extra = true; + + ts_stack_push(stack, 0, trees[2], false, stateB); + ts_stack_push(stack, 0, trees[3], false, stateB); + + StackPopResult pop = ts_stack_pop_pending(stack, 0); + AssertThat(pop.status, Equals(StackPopResult::StackPopSucceeded)); + AssertThat(pop.slices.size, Equals(1)); + + AssertThat(pop.slices.contents[0].trees, Equals(vector({ trees[1], trees[2], trees[3] }))); + + AssertThat(get_stack_entries(stack, 0), Equals(vector({ + {stateA, 0}, + {0, 1}, + }))); + + free_slice_array(&pop.slices); + }); + it("does nothing if the top node was not pushed in pending mode", [&]() { ts_stack_push(stack, 0, trees[1], false, stateB); diff --git a/src/runtime/stack.c b/src/runtime/stack.c index ae3bd51a..59d0fa2d 100644 --- a/src/runtime/stack.c +++ b/src/runtime/stack.c @@ -231,14 +231,17 @@ INLINE StackPopResult stack__iter(Stack *self, StackVersion version, } next_path->node = link.node; - if (!link.is_pending) - next_path->is_pending = false; if (link.tree) { - if (!link.tree->extra) + if (!link.tree->extra) { next_path->tree_count++; + if (!link.is_pending) + next_path->is_pending = false; + } if (!array_push(&next_path->trees, link.tree)) goto error; ts_tree_retain(link.tree); + } else { + next_path->is_pending = false; } } }