Skip to content

Commit

Permalink
[3.12] gh-123048: Fix missing source location in pattern matching code (
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
miss-islington and iritkatriel authored Sep 6, 2024
1 parent 747abc0 commit 919a3e8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Lib/test/test_patma.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import array
import collections
import dataclasses
import dis
import enum
import inspect
import sys
Expand Down Expand Up @@ -3083,6 +3084,24 @@ class Keys:
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):

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

0 comments on commit 919a3e8

Please sign in to comment.