diff --git a/pypy/interpreter/astcompiler/codegen.py b/pypy/interpreter/astcompiler/codegen.py index c2a435a0eb2..d7416023a02 100644 --- a/pypy/interpreter/astcompiler/codegen.py +++ b/pypy/interpreter/astcompiler/codegen.py @@ -1141,7 +1141,7 @@ def visit_TryStar(self, tr): self.emit_op(ops.POP_TOP) self.emit_op(ops.POP_EXCEPT) self.emit_op(ops.POP_TOP) # pypy difference: get rid of unroller - self.emit_jump(ops.JUMP_FORWARD, otherwise) + self.emit_jump(ops.JUMP_FORWARD, end) self.use_next_block(reraise_block) if handler is not None: diff --git a/pypy/interpreter/astcompiler/test/apptest_exceptiongroup.py b/pypy/interpreter/astcompiler/test/apptest_exceptiongroup.py index 76bb2aac469..84a90539d0b 100644 --- a/pypy/interpreter/astcompiler/test/apptest_exceptiongroup.py +++ b/pypy/interpreter/astcompiler/test/apptest_exceptiongroup.py @@ -84,4 +84,21 @@ def test_try_star_name_raise_in_except_handler(): with raises(UnboundLocalError): e1 +def maybe_raise_typeerror(x): + if x: + raise TypeError + +def try_except_star_with_else(x): + try: + maybe_raise_typeerror(x) + except* TypeError: + a = 1 + else: + a = 2 + return a + +def test_try_except_star_with_else(): + assert try_except_star_with_else(True) == 1 + assert try_except_star_with_else(False) == 2 +