summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2019-05-17 10:37:08 (GMT)
committerGitHub <noreply@github.com>2019-05-17 10:37:08 (GMT)
commitaf8646c8054d0f4180a2013383039b6a472f9698 (patch)
treeceafae5989deb1ab62b8237593bd8752ab600e39 /Python/compile.c
parenta8b46944d72bba6dc76260ed61da5c78d3f9d9c0 (diff)
downloadcpython-af8646c8054d0f4180a2013383039b6a472f9698.zip
cpython-af8646c8054d0f4180a2013383039b6a472f9698.tar.gz
cpython-af8646c8054d0f4180a2013383039b6a472f9698.tar.bz2
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.
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 91ce04b..2a086a5 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)) {