@@ -259,7 +259,8 @@ def update(self, reevaluate: bool = True):
259259 elif result != self .stack [self .stack_exec_index + 1 ][0 ].activation_reason :
260260 # In this case, however, the activation reason actually did change. Therefore, we have to
261261 # discard everything in the stack above the current decision and push the new result.
262- self .stack = self .stack [0 : self .stack_exec_index + 1 ]
262+ for _ in range (self .stack_exec_index + 1 , len (self .stack )):
263+ self .stack .pop ()[1 ].on_pop ()
263264 self .stack_reevaluate = False
264265 self .push (tree_element .get_child (result ))
265266
@@ -309,8 +310,9 @@ def pop(self):
309310 if self .stack_reevaluate :
310311 # we are currently reevaluating. we shorten the stack here
311312 if self .stack_exec_index > 0 :
312- # only shorten stack if it still has one element
313- self .stack = self .stack [0 : self .stack_exec_index ]
313+ ## only shorten stack if it still has one element
314+ for _ in range (self .stack_exec_index , len (self .stack )):
315+ self .stack .pop ()[1 ].on_pop ()
314316 # stop reevaluating
315317 self .stack_reevaluate = False
316318 else :
@@ -321,10 +323,10 @@ def pop(self):
321323 # only a single element of the sequence
322324 # We also do not want to reset do_not_reevaluate because an action in the sequence
323325 # may control the stack beyond its own lifetime but in the sequence element's lifetime
324- self .stack [- 1 ][1 ].pop_one ()
326+ self .stack [- 1 ][1 ].pop_one (). on_pop ()
325327 return
326328 # Remove the last element of the stack
327- self .stack .pop ()
329+ self .stack .pop ()[ 1 ]. on_pop ()
328330
329331 # We will reevaluate even when the popped element set do_not_reevaluate
330332 # because no module should control the stack beyond its lifetime
0 commit comments