]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-104635: Add a test case for variables that have a dependency. (gh-106583)
authorDong-hee Na <donghee.na@python.org>
Tue, 11 Jul 2023 01:14:53 +0000 (10:14 +0900)
committerGitHub <noreply@github.com>
Tue, 11 Jul 2023 01:14:53 +0000 (10:14 +0900)
Lib/test/test_compile.py

index 784c0550cc09b10b0553c45a96a89f23b1e5e0fa..85ce0a4b39d8547da2d79e547da0d7c2210a4b95 100644 (file)
@@ -1186,6 +1186,15 @@ class TestSpecifics(unittest.TestCase):
             return a
         self.assertEqual(f("x", "y", "z"), "y")
 
+    def test_variable_dependent(self):
+        # gh-104635: Since the value of b is dependent on the value of a
+        # the first STORE_FAST for a should not be skipped. (e.g POP_TOP).
+        # This test case is added to prevent potential regression from aggressive optimization.
+        def f():
+            a = 42; b = a + 54; a = 54
+            return a, b
+        self.assertEqual(f(), (54, 96))
+
 
 @requires_debug_ranges()
 class TestSourcePositions(unittest.TestCase):