summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMiss Skeleton (bot) <31488909+miss-islington@users.noreply.github.com>2019-10-30 12:11:41 (GMT)
committerGitHub <noreply@github.com>2019-10-30 12:11:41 (GMT)
commitdcb338ea1b8f14e21dde3564658b9040df996349 (patch)
treea3c04f15cb777676c5bfc139c59bc79ade604c76 /Python
parent1d2862a323ae1387e306942253b1e487018e2b7f (diff)
downloadcpython-dcb338ea1b8f14e21dde3564658b9040df996349.zip
cpython-dcb338ea1b8f14e21dde3564658b9040df996349.tar.gz
cpython-dcb338ea1b8f14e21dde3564658b9040df996349.tar.bz2
bpo-38640: Allow break and continue in always false while loops (GH-16992)
(cherry picked from commit 6c3e66a34b95fff07df0ad5086104dd637a091ce) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/compile.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c
index a512e9c..f09e99f 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -2736,7 +2736,15 @@ compiler_while(struct compiler *c, stmt_ty s)
if (constant == 0) {
BEGIN_DO_NOT_EMIT_BYTECODE
+ // Push a dummy block so the VISIT_SEQ knows that we are
+ // inside a while loop so it can correctly evaluate syntax
+ // errors.
+ if (!compiler_push_fblock(c, WHILE_LOOP, NULL, NULL)) {
+ return 0;
+ }
VISIT_SEQ(c, stmt, s->v.While.body);
+ // Remove the dummy block now that is not needed.
+ compiler_pop_fblock(c, WHILE_LOOP, NULL);
END_DO_NOT_EMIT_BYTECODE
if (s->v.While.orelse) {
VISIT_SEQ(c, stmt, s->v.While.orelse);