summaryrefslogtreecommitdiff
path: root/Python/compile.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-05-17 03:59:48 -0700
committerGitHub <noreply@github.com>2019-05-17 03:59:48 -0700
commit85ed1712e428f93408f56fc684816f9a85b0ebc0 (patch)
treeab6f277a93255f5d7a7caa4af7d99d136a568be1 /Python/compile.c
parent94704048e2467dbb4c53ca02d103eab5671e84b3 (diff)
downloadcpython-git-85ed1712e428f93408f56fc684816f9a85b0ebc0.tar.gz
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. (cherry picked from commit af8646c8054d0f4180a2013383039b6a472f9698) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 5688ef8479..d2729d4c6c 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -2301,13 +2301,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)) {