]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-101928: fix crash in compiler on multi-line lambda in function call (#101933)
authorpenguin_wwy <940375606@qq.com>
Thu, 16 Feb 2023 11:31:41 +0000 (19:31 +0800)
committerGitHub <noreply@github.com>
Thu, 16 Feb 2023 11:31:41 +0000 (11:31 +0000)
Lib/test/test_compile.py
Python/compile.c

index 90b067bcf3091276c606faf765283f86b53c45fa..a77742c0cfa6fcb3af0add9cd54f48881de0dc48 100644 (file)
@@ -1155,6 +1155,17 @@ if 1:
             with self.subTest(expr=expr):
                 compile(expr, "<single>", "exec")
 
+    def test_multi_line_lambda_as_argument(self):
+        # See gh-101928
+        compile("""
+def foo(param, lambda_exp):
+    pass
+
+foo(param=0,
+    lambda_exp=lambda:
+    1)
+        """, "<test>", "exec")
+
 
 @requires_debug_ranges()
 class TestSourcePositions(unittest.TestCase):
index 0534b536e3d12eafc0d8ef9f72bca93da00933b8..c3b344c7af2a7f3f0c79906aa48fa41174fc6fa4 100644 (file)
@@ -9085,8 +9085,8 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts)
                         Py_DECREF(cnt);
                         break;
                     case RETURN_VALUE:
-                        INSTR_SET_OP1(inst, RETURN_CONST, oparg);
-                        INSTR_SET_OP0(&bb->b_instr[i + 1], NOP);
+                        INSTR_SET_OP0(inst, NOP);
+                        INSTR_SET_OP1(&bb->b_instr[++i], RETURN_CONST, oparg);
                         break;
                 }
                 break;