diff --git a/mypyc/irbuild/statement.py b/mypyc/irbuild/statement.py index a3e571b633776..d96ec47a3ffed 100644 --- a/mypyc/irbuild/statement.py +++ b/mypyc/irbuild/statement.py @@ -712,6 +712,9 @@ def transform_try_except( builder.builder.push_error_handler(double_except_block) builder.activate_block(except_entry) old_exc = builder.call_c(error_catch_op, [], line) + if builder.fn_info.is_generator: + # CFG cleanup may remove the CallC's block while resume cleanup paths remain. + old_exc = builder.ensure_register(old_exc) # Compile the except blocks with the nonlocal control flow overridden to clear exc_info builder.nonlocal_control.append(ExceptNonlocalControl(builder.nonlocal_control[-1], old_exc)) diff --git a/mypyc/test-data/run-async.test b/mypyc/test-data/run-async.test index 9a729f8fff461..5eebb7348cf35 100644 --- a/mypyc/test-data/run-async.test +++ b/mypyc/test-data/run-async.test @@ -292,8 +292,12 @@ async def async_with_vectorcall() -> str: async with ctx: return await async_val("vc") +async def async_with_pass() -> None: + async with async_ctx(): + pass + [file driver.py] -from native import async_with, async_with_vectorcall +from native import async_with, async_with_pass, async_with_vectorcall from testutil import run_generator yields, val = run_generator(async_with(), [None, 'x', None]) @@ -304,6 +308,10 @@ yields, val = run_generator(async_with_vectorcall(), [None, 'x', None]) assert yields == ('enter', 'vc', 'exit'), yields assert val == 'x', val +yields, val = run_generator(async_with_pass(), [None, None]) +assert yields == ('enter', 'exit'), yields +assert val is None + [case testAsyncReturn] from testutil import async_val