diff options
| author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-01-24 22:51:18 (GMT) |
|---|---|---|
| committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-01-24 22:51:18 (GMT) |
| commit | 16570f59caecde43b13b0e5f4c9328e4ceded544 (patch) | |
| tree | 4e85aacb3816816b40bc6e099313b234734781b0 /Lib/test/test_grammar.py | |
| parent | 5310b6941965afa3a40e61e8315590c931dc47e6 (diff) | |
| download | cpython-16570f59caecde43b13b0e5f4c9328e4ceded544.zip cpython-16570f59caecde43b13b0e5f4c9328e4ceded544.tar.gz cpython-16570f59caecde43b13b0e5f4c9328e4ceded544.tar.bz2 | |
#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 'Lib/test/test_grammar.py')
| -rw-r--r-- | Lib/test/test_grammar.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index 4352275..d4bcfda 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -572,6 +572,15 @@ hello world 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 + self.assertEquals(x, 2) + def testFor(self): # 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite] for i in 1, 2, 3: pass |
