diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-09-17 15:17:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-17 15:17:29 +0300 |
commit | da8d72c953369b872a12c13f136ada77a786714a (patch) | |
tree | bcfb6546be24ecf3efaee838934001fd931fa065 /Python/compile.c | |
parent | 5e99b56d6b249995a4fa2bc09c0bb03841f49572 (diff) | |
download | cpython-git-da8d72c953369b872a12c13f136ada77a786714a.tar.gz |
bpo-12458: Fix line numbers for multiline expressions. (GH-8774)
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/Python/compile.c b/Python/compile.c index c6a667c29e..ebd73fb723 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -4089,10 +4089,6 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type, is_async_generator = c->u->u_ste->ste_coroutine; if (is_async_generator && !is_async_function && type != COMP_GENEXP) { - if (e->lineno > c->u->u_lineno) { - c->u->u_lineno = e->lineno; - c->u->u_lineno_set = 0; - } compiler_error(c, "asynchronous comprehension outside of " "an asynchronous function"); goto error_in_scope; @@ -4430,17 +4426,8 @@ compiler_with(struct compiler *c, stmt_ty s, int pos) } static int -compiler_visit_expr(struct compiler *c, expr_ty e) +compiler_visit_expr1(struct compiler *c, expr_ty e) { - /* If expr e has a different line number than the last expr/stmt, - set a new line number for the next instruction. - */ - if (e->lineno > c->u->u_lineno) { - c->u->u_lineno = e->lineno; - c->u->u_lineno_set = 0; - } - /* Updating the column offset is always harmless. */ - c->u->u_col_offset = e->col_offset; switch (e->kind) { case BoolOp_kind: return compiler_boolop(c, e); @@ -4610,6 +4597,31 @@ compiler_visit_expr(struct compiler *c, expr_ty e) } static int +compiler_visit_expr(struct compiler *c, expr_ty e) +{ + /* If expr e has a different line number than the last expr/stmt, + set a new line number for the next instruction. + */ + int old_lineno = c->u->u_lineno; + int old_col_offset = c->u->u_col_offset; + if (e->lineno != c->u->u_lineno) { + c->u->u_lineno = e->lineno; + c->u->u_lineno_set = 0; + } + /* Updating the column offset is always harmless. */ + c->u->u_col_offset = e->col_offset; + + int res = compiler_visit_expr1(c, e); + + if (old_lineno != c->u->u_lineno) { + c->u->u_lineno = old_lineno; + c->u->u_lineno_set = 0; + } + c->u->u_col_offset = old_col_offset; + return res; +} + +static int compiler_augassign(struct compiler *c, stmt_ty s) { expr_ty e = s->v.AugAssign.target; |