diff --git a/mypyc/irbuild/statement.py b/mypyc/irbuild/statement.py index b109d925558b..16a0483a8729 100644 --- a/mypyc/irbuild/statement.py +++ b/mypyc/irbuild/statement.py @@ -940,6 +940,10 @@ def emit_yield_from_or_await( # If it wasn't, this reraises the exception. builder.activate_block(stop_block) builder.assign(result, builder.call_c(check_stop_op, [], line), line) + # Clear the spilled iterator/coroutine so that it will be freed. + # Otherwise, the freeing of the spilled register would likely be delayed. + err = builder.add(LoadErrorValue(object_rprimitive)) + builder.assign(iter_reg, err, line) builder.goto(done_block) builder.activate_block(main_block)