#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.
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index 76483f6..89e9e67 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -511,6 +511,15 @@
while 0: pass
else: pass
+# Issue1920: "while 0" is optimized away,
+# ensure that the "else" clause is still present.
+x = 0
+while 0:
+ x = 1
+else:
+ x = 2
+assert x == 2
+
print 'for_stmt' # 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite]
for i in 1, 2, 3: pass
for i, j, k in (): pass