]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-123048: Fix missing source location in pattern matching code (GH-123167...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 6 Sep 2024 10:43:05 +0000 (12:43 +0200)
committerGitHub <noreply@github.com>
Fri, 6 Sep 2024 10:43:05 +0000 (10:43 +0000)
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>
Lib/test/test_patma.py
Misc/NEWS.d/next/Core and Builtins/2024-08-20-11-09-16.gh-issue-123048.2TISpv.rst [new file with mode: 0644]

index 3dbd19dfffd31861ac20a3b5e0dcd7d5b974b179..6fe5360b5f296a6b3f0b43e5c0e9ce7645e269b3 100644 (file)
@@ -1,6 +1,7 @@
 import array
 import collections
 import dataclasses
+import dis
 import enum
 import inspect
 import sys
@@ -3083,6 +3084,24 @@ class TestValueErrors(unittest.TestCase):
         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):
 
diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-08-20-11-09-16.gh-issue-123048.2TISpv.rst b/Misc/NEWS.d/next/Core and Builtins/2024-08-20-11-09-16.gh-issue-123048.2TISpv.rst
new file mode 100644 (file)
index 0000000..f0b756f
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a bug where pattern matching code could emit a :opcode:`JUMP_FORWARD`
+with no source location.