From 1b76a9d70515cc98d9772c72daadbf2634aa788f Mon Sep 17 00:00:00 2001 From: George Marques Date: Mon, 23 May 2022 21:38:31 -0300 Subject: GDScript: Fix lambda captures in default argument values --- modules/gdscript/gdscript_parser.cpp | 3 +++ .../scripts/parser/features/lambda_default_parameter_capture.gd | 7 +++++++ .../scripts/parser/features/lambda_default_parameter_capture.out | 2 ++ 3 files changed, 12 insertions(+) create mode 100644 modules/gdscript/tests/scripts/parser/features/lambda_default_parameter_capture.gd create mode 100644 modules/gdscript/tests/scripts/parser/features/lambda_default_parameter_capture.out diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index f23cddcbda..b93fff3914 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -2926,6 +2926,9 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_lambda(ExpressionNode *p_p current_function = function; SuiteNode *body = alloc_node(); + body->parent_function = current_function; + body->parent_block = current_suite; + SuiteNode *previous_suite = current_suite; current_suite = body; diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_default_parameter_capture.gd b/modules/gdscript/tests/scripts/parser/features/lambda_default_parameter_capture.gd new file mode 100644 index 0000000000..2140b6923e --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/lambda_default_parameter_capture.gd @@ -0,0 +1,7 @@ +# https://github.com/godotengine/godot/issues/56751 + +func test(): + var x = "local" + var lambda = func(param = x): + print(param) + lambda.call() diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_default_parameter_capture.out b/modules/gdscript/tests/scripts/parser/features/lambda_default_parameter_capture.out new file mode 100644 index 0000000000..ce3241b94d --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/lambda_default_parameter_capture.out @@ -0,0 +1,2 @@ +GDTEST_OK +local -- cgit v1.2.3