Skip to content
Snippets Groups Projects
Commit 12ce9f26 authored by Damien George's avatar Damien George
Browse files

py/compile: Fix handling of unwinding BaseException in async with.

All exceptions that unwind through the async-with must be caught and
BaseException is the top-level class, which includes Exception and others.

Fixes issue #4552.
parent 823b31e5
No related branches found
No related tags found
No related merge requests found
...@@ -1830,7 +1830,7 @@ STATIC void compile_async_with_stmt_helper(compiler_t *comp, int n, mp_parse_nod ...@@ -1830,7 +1830,7 @@ STATIC void compile_async_with_stmt_helper(compiler_t *comp, int n, mp_parse_nod
// Detect if TOS an exception or not // Detect if TOS an exception or not
EMIT(dup_top); EMIT(dup_top);
EMIT_LOAD_GLOBAL(MP_QSTR_Exception); EMIT_LOAD_GLOBAL(MP_QSTR_BaseException);
EMIT_ARG(binary_op, MP_BINARY_OP_EXCEPTION_MATCH); EMIT_ARG(binary_op, MP_BINARY_OP_EXCEPTION_MATCH);
EMIT_ARG(pop_jump_if, false, l_ret_unwind_jump); // if not an exception then we have case 3 EMIT_ARG(pop_jump_if, false, l_ret_unwind_jump); // if not an exception then we have case 3
......
...@@ -27,3 +27,13 @@ try: ...@@ -27,3 +27,13 @@ try:
o.send(None) o.send(None)
except ValueError: except ValueError:
print('ValueError') print('ValueError')
# test raising BaseException to make sure it is handled by the async-with
async def h():
async with AContext():
raise BaseException
o = h()
try:
o.send(None)
except BaseException:
print('BaseException')
...@@ -6,3 +6,6 @@ enter ...@@ -6,3 +6,6 @@ enter
1 1
exit <class 'ValueError'> error exit <class 'ValueError'> error
ValueError ValueError
enter
exit <class 'BaseException'>
BaseException
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment