From 099b2a659adc78542d0805c95cef76acd6991499 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Mon, 30 Jan 2023 08:54:02 +0900 Subject: [PATCH] gh-101400: Restore continue/break loc for the non-loop case --- .../2023-01-30-08-59-47.gh-issue-101400.Di_ZFm.rst | 1 + Python/compile.c | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-01-30-08-59-47.gh-issue-101400.Di_ZFm.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-01-30-08-59-47.gh-issue-101400.Di_ZFm.rst b/Misc/NEWS.d/next/Core and Builtins/2023-01-30-08-59-47.gh-issue-101400.Di_ZFm.rst new file mode 100644 index 000000000000000..2bda3b05a6fb8a2 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-01-30-08-59-47.gh-issue-101400.Di_ZFm.rst @@ -0,0 +1 @@ +Restore continue/break loc for the non-loop case. Patch by Dong-hee Na. diff --git a/Python/compile.c b/Python/compile.c index c31f08c0a1797bc..70d05af58161f93 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;