summaryrefslogtreecommitdiff
path: root/Python/compile.c
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-01-24 22:51:18 +0000
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-01-24 22:51:18 +0000
commitf5ef5d021202f0e42b56863d8b24938a3b05f748 (patch)
treef084a804bebd02024cfbefcd94c4aa9478f75175 /Python/compile.c
parentad205f4dc03bcb2cac097ca598a527638632515b (diff)
downloadcpython-f5ef5d021202f0e42b56863d8b24938a3b05f748.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. Will backport.
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Python/compile.c b/Python/compile.c
index c77091ea25..aee7bda9ae 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1598,8 +1598,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) {