@@ -1544,22 +1544,19 @@ impl ExecutingFrame<'_> {
15441544 // CPython bytecodes.c:1146: inst(RERAISE, (values[oparg], exc -- values[oparg]))
15451545 //
15461546 // Stack layout: [values..., exc] where len(values) == oparg
1547- // If oparg > 0: values[0] is lasti (for traceback purposes in CPython).
1548- // Then we pop exc and reraise it.
1549- //
1550- // IMPORTANT: In CPython, RERAISE sets frame->instr_ptr to lasti for traceback,
1551- // but exception_unwind uses next_instr (not frame->instr_ptr) to find handlers.
1552- // This means the exception table lookup uses RERAISE's position, NOT the
1553- // original exception position.
1554- //
1555- // In RustPython, we use self.lasti for exception handler lookup, so we should
1556- // NOT modify lasti here. The exception's traceback is already set correctly.
1557- // We just pop exc and reraise it.
1558- let _depth_val = depth. get ( arg) ;
1547+ // RERAISE pops exc and oparg additional values from the stack.
1548+ // In CPython, values[0] is lasti used to set frame->instr_ptr for traceback.
1549+ // We skip the lasti update since RustPython's traceback is already correct.
1550+ let depth_val = depth. get ( arg) as usize ;
15591551
1560- // Pop exception from TOS only (values remain on stack for cleanup)
1552+ // Pop exception from TOS
15611553 let exc = self . pop_value ( ) ;
15621554
1555+ // Pop the depth values (lasti and possibly other items like prev_exc)
1556+ for _ in 0 ..depth_val {
1557+ self . pop_value ( ) ;
1558+ }
1559+
15631560 if let Some ( exc_ref) = exc. downcast_ref :: < PyBaseException > ( ) {
15641561 Err ( exc_ref. to_owned ( ) )
15651562 } else {
0 commit comments