8000 gh-107901: Fix missing line number on BACKWARD_JUMP at the end of a f… · python/cpython@a1cc74c · GitHub
[go: up one dir, main page]

Skip to content

Commit a1cc74c

Browse files
authored
gh-107901: Fix missing line number on BACKWARD_JUMP at the end of a for loop (#108242)
1 parent e6db23f commit a1cc74c

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Lib/test/test_compile.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,20 @@ async def test(aseq):
10311031
code_lines = self.get_code_lines(test.__code__)
10321032
self.assertEqual(expected_lines, code_lines)
10331033

1034+
def test_lineno_of_backward_jump(self):
1035+
# Issue gh-107901
1036+
def f():
1037+
for i in x:
1038+
if y:
1039+
pass
1040+
1041+
linenos = list(inst.positions.lineno
1042+
8000 for inst in dis.get_instructions(f.__code__)
1043+
if inst.opname == 'JUMP_BACKWARD')
1044+
1045+
self.assertTrue(len(linenos) > 0)
1046+
self.assertTrue(all(l is not None for l in linenos))
1047+
10341048
def test_big_dict_literal(self):
10351049
# The compiler has a flushing point in "compiler_dict" that calls compiles
10361050
# a portion of the dictionary literal when the loop that iterates over the items
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix missing line number on :opcode:`JUMP_BACKWARD` at the end of a for loop.

Python/flowgraph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ normalize_jumps_in_block(cfg_builder *g, basicblock *b) {
531531
if (backwards_jump == NULL) {
532532
return ERROR;
533533
}
534-
basicblock_addop(backwards_jump, JUMP, target->b_label.id, NO_LOCATION);
534+
basicblock_addop(backwards_jump, JUMP, target->b_label.id, last->i_loc);
535535
backwards_jump->b_instr[0].i_target = target;
536536
last->i_opcode = reversed_opcode;
537537
last->i_target = b->b_next;

0 commit comments

Comments
 (0)
0