There was an error while loading. Please reload this page.
1 parent 77133f5 commit bffed80Copy full SHA for bffed80
3 files changed
Lib/test/test_patma.py
@@ -1,6 +1,7 @@
1
import array
2
import collections
3
import dataclasses
4
+import dis
5
import enum
6
import inspect
7
import sys
@@ -3377,6 +3378,24 @@ class Keys:
3377
3378
self.assertIs(y, None)
3379
self.assertIs(z, None)
3380
3381
+class TestSourceLocations(unittest.TestCase):
3382
+ def test_jump_threading(self):
3383
+ # See gh-123048
3384
+ def f():
3385
+ x = 0
3386
+ v = 1
3387
+ match v:
3388
+ case 1:
3389
+ if x < 0:
3390
+ x = 1
3391
+ case 2:
3392
3393
3394
+ x += 1
3395
+
3396
+ for inst in dis.get_instructions(f):
3397
+ if inst.opcode in dis.hasjump:
3398
+ self.assertIsNotNone(inst.positions.lineno, "jump without location")
3399
3400
class TestTracing(unittest.TestCase):
3401
Misc/NEWS.d/next/Core and Builtins/2024-08-20-11-09-16.gh-issue-123048.2TISpv.rst
@@ -0,0 +1,2 @@
+Fix a bug where pattern matching code could emit a :opcode:`JUMP_FORWARD`
+with no source location.
Python/compile.c
@@ -7301,7 +7301,7 @@ codegen_match_inner(struct compiler *c, stmt_ty s, pattern_context *pc)
7301
ADDOP(c, LOC(m->pattern), POP_TOP);
7302
}
7303
VISIT_SEQ(c, stmt, m->body);
7304
- ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, end);
+ ADDOP_JUMP(c, NO_LOCATION, JUMP, end);
7305
// If the pattern fails to match, we want the line number of the
7306
// cleanup to be associated with the failed pattern, not the last line
7307
// of the body
0 commit comments