[Python-checkins] gh-101928: fix crash in compiler on multi-line lambda in function call (#101933)

iritkatriel webhook-mailer at python.org
Thu Feb 16 06:31:49 EST 2023


https://github.com/python/cpython/commit/df7ccf6138b1a2ce0b82ff06aa3497ca4d38c90d
commit: df7ccf6138b1a2ce0b82ff06aa3497ca4d38c90d
branch: main
author: penguin_wwy <940375606 at qq.com>
committer: iritkatriel <1055913+iritkatriel at users.noreply.github.com>
date: 2023-02-16T11:31:41Z
summary:

gh-101928: fix crash in compiler on multi-line lambda in function call (#101933)

files:
M Lib/test/test_compile.py
M Python/compile.c

diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 90b067bcf309..a77742c0cfa6 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -1155,6 +1155,17 @@ def test_if_expression_expression_empty_block(self):
             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):
diff --git a/Python/compile.c b/Python/compile.c
index 0534b536e3d1..c3b344c7af2a 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -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;



More information about the Python-checkins mailing list