gh-123048: Fix missing source location in pattern matching code (GH-123167)
(cherry picked from commit
bffed80230f2617de2ee02bd4bdded1024234dab)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
import array
import collections
import dataclasses
+import dis
import enum
import inspect
import sys
self.assertIs(y, None)
self.assertIs(z, None)
+class TestSourceLocations(unittest.TestCase):
+ def test_jump_threading(self):
+ # See gh-123048
+ def f():
+ x = 0
+ v = 1
+ match v:
+ case 1:
+ if x < 0:
+ x = 1
+ case 2:
+ if x < 0:
+ x = 1
+ x += 1
+
+ for inst in dis.get_instructions(f):
+ if inst.opcode in dis.hasjrel or inst.opcode in dis.hasjabs:
+ self.assertIsNotNone(inst.positions.lineno, "jump without location")
class TestTracing(unittest.TestCase):
--- /dev/null
+Fix a bug where pattern matching code could emit a :opcode:`JUMP_FORWARD`
+with no source location.