gh-156466: ensure in codegen that a pushed COMPILE_FBLOCK_ASYNC_COMPREHENSION_GENERATOR is always popped - #157338
Conversation
| int ret = codegen_async_comprehension_generator_body( | ||
| c, loc, generators, gen_index, depth, elt, val, type, avoid_creation, | ||
| gen, start); | ||
| _PyCompile_PopFBlock(c, COMPILE_FBLOCK_ASYNC_COMPREHENSION_GENERATOR, start); |
There was a problem hiding this comment.
This can pop the wrong block after a codegen error in a nested inlined comprehension. For example, compiling this source aborts a debug build:
async def f(it):
return [[f(a=1, a=2) for y in z] async for x in it]I verified that the parent commit raises SyntaxError: keyword argument repeated: a, while this PR aborts on the block-type assertion in _PyCompile_PopFBlock.
The inner comprehension leaves its COMPILE_FBLOCK_INLINED_COMPREHENSION pushed when codegen_comprehension takes its error path, so it is still above the async block when we get here. Could we make sure nested inlined-comprehension blocks are cleaned up on error before making this pop unconditional, and add a regression test for this case?
|
When you're done making the requested changes, leave the comment: |
In case of error after
COMPILE_FBLOCK_ASYNC_COMPREHENSION_GENERATORis pushed, it was not always popped. This hasn't caused a problem in main AFAIK, but it was exposed during work on gh-156819 when compiling the invalid syntax{a async for b in d for *(b,) in e}.