mirror of
https://github.com/python/cpython.git
synced 2026-01-30 03:02:30 +00:00
#1920: when considering a block starting by "while 0", the compiler optimized the
whole construct away, even when an 'else' clause is present::
while 0:
print("no")
else:
print("yes")
did not generate any code at all.
Now the compiler emits the 'else' block, like it already does for 'if' statements.
Backport of r60265.
This commit is contained in:
parent
d933e0a7d3
commit
f1a7178cd5
3 changed files with 18 additions and 1 deletions
|
|
@ -2256,8 +2256,11 @@ compiler_while(struct compiler *c, stmt_ty s)
|
|||
basicblock *loop, *orelse, *end, *anchor = NULL;
|
||||
int constant = expr_constant(s->v.While.test);
|
||||
|
||||
if (constant == 0)
|
||||
if (constant == 0) {
|
||||
if (s->v.While.orelse)
|
||||
VISIT_SEQ(c, stmt, s->v.While.orelse);
|
||||
return 1;
|
||||
}
|
||||
loop = compiler_new_block(c);
|
||||
end = compiler_new_block(c);
|
||||
if (constant == -1) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue