Skip to content

Commit 919a3e8

Browse files
[3.12] gh-123048: Fix missing source location in pattern matching code (GH-123167) (#123170)
gh-123048: Fix missing source location in pattern matching code (GH-123167) (cherry picked from commit bffed80) Co-authored-by: Irit Katriel <[email protected]>
1 parent 747abc0 commit 919a3e8

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Lib/test/test_patma.py

+19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import array
22
import collections
33
import dataclasses
4+
import dis
45
import enum
56
import inspect
67
import sys
@@ -3083,6 +3084,24 @@ class Keys:
30833084
self.assertIs(y, None)
30843085
self.assertIs(z, None)
30853086

3087+
class TestSourceLocations(unittest.TestCase):
3088+
def test_jump_threading(self):
3089+
# See gh-123048
3090+
def f():
3091+
x = 0
3092+
v = 1
3093+
match v:
3094+
case 1:
3095+
if x < 0:
3096+
x = 1
3097+
case 2:
3098+
if x < 0:
3099+
x = 1
3100+
x += 1
3101+
3102+
for inst in dis.get_instructions(f):
3103+
if inst.opcode in dis.hasjrel or inst.opcode in dis.hasjabs:
3104+
self.assertIsNotNone(inst.positions.lineno, "jump without location")
30863105

30873106
class TestTracing(unittest.TestCase):
30883107

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a bug where pattern matching code could emit a :opcode:`JUMP_FORWARD`
2+
with no source location.

0 commit comments

Comments
 (0)