summaryrefslogtreecommitdiff
path: root/Python/compile.c
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na@python.org>2023-01-31 23:42:22 +0900
committerGitHub <noreply@github.com>2023-01-31 23:42:22 +0900
commit740050af0493030b1f6ebf0b9ac39a356e2e74b6 (patch)
tree322b8915045b9d9fe03a69982efc5558306714ad /Python/compile.c
parent71db9c9ea50ccba47a3c1e31334747049a68487b (diff)
downloadcpython-git-740050af0493030b1f6ebf0b9ac39a356e2e74b6.tar.gz
[3.10] gh-101400: Fix incorrect lineno in exception message on contin… (gh-101448)
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c
index e5438f7d00..80caa8fab1 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);