[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 bffed80230)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2024-09-06 12:43:05 +02:00 committed by GitHub
parent 747abc00d0
commit 919a3e8028
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View file

@ -1,6 +1,7 @@
import array import array
import collections import collections
import dataclasses import dataclasses
import dis
import enum import enum
import inspect import inspect
import sys import sys
@ -3083,6 +3084,24 @@ class TestValueErrors(unittest.TestCase):
self.assertIs(y, None) self.assertIs(y, None)
self.assertIs(z, 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): class TestTracing(unittest.TestCase):

View file

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