Browse Source

GDScript: Fix lambda captures in default argument values

George Marques 3 years ago
parent
commit
1b76a9d705

+ 3 - 0
modules/gdscript/gdscript_parser.cpp

@@ -2926,6 +2926,9 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_lambda(ExpressionNode *p_p
 	current_function = function;
 
 	SuiteNode *body = alloc_node<SuiteNode>();
+	body->parent_function = current_function;
+	body->parent_block = current_suite;
+
 	SuiteNode *previous_suite = current_suite;
 	current_suite = body;
 

+ 7 - 0
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()

+ 2 - 0
modules/gdscript/tests/scripts/parser/features/lambda_default_parameter_capture.out

@@ -0,0 +1,2 @@
+GDTEST_OK
+local