diff options
author | Dong-hee Na <donghee.na@python.org> | 2023-01-31 14:42:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-31 14:42:22 (GMT) |
commit | 740050af0493030b1f6ebf0b9ac39a356e2e74b6 (patch) | |
tree | 322b8915045b9d9fe03a69982efc5558306714ad /Python | |
parent | 71db9c9ea50ccba47a3c1e31334747049a68487b (diff) | |
download | cpython-740050af0493030b1f6ebf0b9ac39a356e2e74b6.zip cpython-740050af0493030b1f6ebf0b9ac39a356e2e74b6.tar.gz cpython-740050af0493030b1f6ebf0b9ac39a356e2e74b6.tar.bz2 |
[3.10] gh-101400: Fix incorrect lineno in exception message on contin… (gh-101448)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/compile.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c index e5438f7..80caa8f 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3030,12 +3030,14 @@ static int compiler_break(struct compiler *c) { struct fblockinfo *loop = NULL; + int origin_loc = c->u->u_lineno; /* Emit instruction with line number */ ADDOP(c, NOP); if (!compiler_unwind_fblock_stack(c, 0, &loop)) { return 0; } if (loop == NULL) { + c->u->u_lineno = origin_loc; return compiler_error(c, "'break' outside loop"); } if (!compiler_unwind_fblock(c, loop, 0)) { @@ -3050,12 +3052,14 @@ static int compiler_continue(struct compiler *c) { struct fblockinfo *loop = NULL; + int origin_loc = c->u->u_lineno; /* Emit instruction with line number */ ADDOP(c, NOP); if (!compiler_unwind_fblock_stack(c, 0, &loop)) { return 0; } if (loop == NULL) { + c->u->u_lineno = origin_loc; return compiler_error(c, "'continue' not properly in loop"); } ADDOP_JUMP(c, JUMP_ABSOLUTE, loop->fb_block); |