From af8646c8054d0f4180a2013383039b6a472f9698 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Fri, 17 May 2019 11:37:08 +0100 Subject: bpo-1875: Raise SyntaxError in invalid blocks that will be optimised away (GH-13332) Move the check for dead conditionals (if 0) to the peephole optimizer and make sure that the code block is still compiled to report any existing syntax errors within. --- Python/compile.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'Python/compile.c') diff --git a/Python/compile.c b/Python/compile.c index 91ce04b02e..2a086a509f 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -2546,13 +2546,12 @@ compiler_if(struct compiler *c, stmt_ty s) return 0; constant = expr_constant(s->v.If.test); - /* constant = 0: "if 0" + /* constant = 0: "if 0" Leave the optimizations to + * the pephole optimizer to check for syntax errors + * in the block. * constant = 1: "if 1", "if 2", ... * constant = -1: rest */ - if (constant == 0) { - if (s->v.If.orelse) - VISIT_SEQ(c, stmt, s->v.If.orelse); - } else if (constant == 1) { + if (constant == 1) { VISIT_SEQ(c, stmt, s->v.If.body); } else { if (asdl_seq_LEN(s->v.If.orelse)) { -- cgit v1.2.1