From 6c3e66a34b95fff07df0ad5086104dd637a091ce Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Wed, 30 Oct 2019 11:53:26 +0000 Subject: bpo-38640: Allow break and continue in always false while loops (GH-16992) --- Python/compile.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'Python/compile.c') diff --git a/Python/compile.c b/Python/compile.c index 3b2188e6e74..f26ad3c7752 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -2738,7 +2738,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); -- cgit v1.2.3