summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-01-24 23:42:08 +0000
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-01-24 23:42:08 +0000
commitf1a7178cd569383cbce3aba22bd7b1d5950e7c20 (patch)
tree9e575034a9f6eed2ccb84329ea47414330c7caf9 /Python
parentd933e0a7d3656a0d08bedb1eddb6347fb7dda4ec (diff)
downloadcpython-git-f1a7178cd569383cbce3aba22bd7b1d5950e7c20.tar.gz
#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.
Diffstat (limited to 'Python')
-rw-r--r--Python/compile.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 0e824caabd..8e96ddfa62 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -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) {