diff Python/compile.c @ 44928:69c5703d20fb legacy-trunk

#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.
author Amaury Forgeot d'Arc <amauryfa@gmail.com>
date Thu, 24 Jan 2008 22:51:18 +0000
parents 0ad12c79af18
children 1c9ac00c4758
line wrap: on
line diff
--- a/Python/compile.c	Thu Jan 24 21:47:56 2008 +0000
+++ b/Python/compile.c	Thu Jan 24 22:51:18 2008 +0000
@@ -1598,8 +1598,11 @@
 	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) {