From 60e719a5c757576f318629b650799465c162cb3b Mon Sep 17 00:00:00 2001 From: penguin-wwy <940375606@qq.com> Date: Wed, 15 Feb 2023 20:30:23 +0800 Subject: [PATCH 1/2] Fix crash caused by RETURN_CONST --- Python/compile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python/compile.c b/Python/compile.c index 0534b536e3d12e..c3b344c7af2a7f 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; From a0822855418be733d7b29405d065cc43bf7c22c5 Mon Sep 17 00:00:00 2001 From: penguin-wwy <940375606@qq.com> Date: Thu, 16 Feb 2023 11:15:53 +0800 Subject: [PATCH 2/2] Add unittest --- Lib/test/test_compile.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 90b067bcf30912..a77742c0cfa6fc 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, "", "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) + """, "", "exec") + @requires_debug_ranges() class TestSourcePositions(unittest.TestCase):