diff options
author | Dong-hee Na <donghee.na@python.org> | 2023-01-30 23:33:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-30 23:33:54 (GMT) |
commit | e867c1b753424d8d3f9c9ba0b431d007fd958c80 (patch) | |
tree | 9def8e6c605998963cb4483da7110cf490410bad /Python/compile.c | |
parent | 28db978d7f134edf6c86f21c42e15003511e7e9b (diff) | |
download | cpython-e867c1b753424d8d3f9c9ba0b431d007fd958c80.zip cpython-e867c1b753424d8d3f9c9ba0b431d007fd958c80.tar.gz cpython-e867c1b753424d8d3f9c9ba0b431d007fd958c80.tar.bz2 |
gh-101400: Fix incorrect lineno in exception message on continue/break which are not in a loop (#101413)
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Python/compile.c b/Python/compile.c index c31f08c..70d05af 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3246,11 +3246,12 @@ static int compiler_break(struct compiler *c, location loc) { struct fblockinfo *loop = NULL; + location origin_loc = loc; /* Emit instruction with line number */ ADDOP(c, loc, NOP); RETURN_IF_ERROR(compiler_unwind_fblock_stack(c, &loc, 0, &loop)); if (loop == NULL) { - return compiler_error(c, loc, "'break' outside loop"); + return compiler_error(c, origin_loc, "'break' outside loop"); } RETURN_IF_ERROR(compiler_unwind_fblock(c, &loc, loop, 0)); ADDOP_JUMP(c, loc, JUMP, loop->fb_exit); @@ -3261,11 +3262,12 @@ static int compiler_continue(struct compiler *c, location loc) { struct fblockinfo *loop = NULL; + location origin_loc = loc; /* Emit instruction with line number */ ADDOP(c, loc, NOP); RETURN_IF_ERROR(compiler_unwind_fblock_stack(c, &loc, 0, &loop)); if (loop == NULL) { - return compiler_error(c, loc, "'continue' not properly in loop"); + return compiler_error(c, origin_loc, "'continue' not properly in loop"); } ADDOP_JUMP(c, loc, JUMP, loop->fb_block); return SUCCESS; |