@@ -259,7 +259,8 @@ def update(self, reevaluate: bool = True):
259
259
elif result != self .stack [self .stack_exec_index + 1 ][0 ].activation_reason :
260
260
# In this case, however, the activation reason actually did change. Therefore, we have to
261
261
# 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 ()
263
264
self .stack_reevaluate = False
264
265
self .push (tree_element .get_child (result ))
265
266
@@ -309,8 +310,9 @@ def pop(self):
309
310
if self .stack_reevaluate :
310
311
# we are currently reevaluating. we shorten the stack here
311
312
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 ()
314
316
# stop reevaluating
315
317
self .stack_reevaluate = False
316
318
else :
@@ -321,10 +323,10 @@ def pop(self):
321
323
# only a single element of the sequence
322
324
# We also do not want to reset do_not_reevaluate because an action in the sequence
323
325
# 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 ()
325
327
return
326
328
# Remove the last element of the stack
327
- self .stack .pop ()
329
+ self .stack .pop ()[ 1 ]. on_pop ()
328
330
329
331
# We will reevaluate even when the popped element set do_not_reevaluate
330
332
# because no module should control the stack beyond its lifetime
0 commit comments