From 89429b0273a3358f4a0a283abf7efa7fcb4e5e4c Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Wed, 23 Aug 2023 12:37:18 +0300 Subject: GDScript: Fix lambda resolution with cyclic references --- .../analyzer/errors/lambda_cyclic_ref_call_arg.gd | 5 ++++ .../analyzer/errors/lambda_cyclic_ref_call_arg.out | 2 ++ .../analyzer/errors/lambda_cyclic_ref_param.gd | 5 ++++ .../analyzer/errors/lambda_cyclic_ref_param.out | 2 ++ .../analyzer/features/lambda_cyclic_ref_body.gd | 34 ++++++++++++++++++++++ .../analyzer/features/lambda_cyclic_ref_body.out | 5 ++++ 6 files changed, 53 insertions(+) create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_call_arg.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_call_arg.out create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_param.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_param.out create mode 100644 modules/gdscript/tests/scripts/analyzer/features/lambda_cyclic_ref_body.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/features/lambda_cyclic_ref_body.out (limited to 'modules/gdscript/tests/scripts/analyzer') diff --git a/modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_call_arg.gd b/modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_call_arg.gd new file mode 100644 index 0000000000..4b72fb9daa --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_call_arg.gd @@ -0,0 +1,5 @@ +var f = (func (_a): return 0).call(x) +var x = f + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_call_arg.out b/modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_call_arg.out new file mode 100644 index 0000000000..6bca25b330 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_call_arg.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Could not resolve member "f": Cyclic reference. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_param.gd b/modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_param.gd new file mode 100644 index 0000000000..115e8be50a --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_param.gd @@ -0,0 +1,5 @@ +var f = func (_a = x): return 0 +var x = f + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_param.out b/modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_param.out new file mode 100644 index 0000000000..6bca25b330 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_param.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Could not resolve member "f": Cyclic reference. diff --git a/modules/gdscript/tests/scripts/analyzer/features/lambda_cyclic_ref_body.gd b/modules/gdscript/tests/scripts/analyzer/features/lambda_cyclic_ref_body.gd new file mode 100644 index 0000000000..e2f41a652c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/lambda_cyclic_ref_body.gd @@ -0,0 +1,34 @@ +# GH-70592 + +var f: Callable = func (): + x = 2 + return 1 + +var x: int = f.call() + +var g: Array[Callable] = [ + func (): + y += 10 + return 1, + func (): + y += 20 + return 2, +] + +var y: int = g[0].call() + g[1].call() + +func test(): + print(x) + f.call() + print(x) + + print(y) + g[0].call() + g[1].call() + print(y) + + # This prevents memory leak in CI. TODO: Investigate it. + # Also you cannot run the `EditorScript` twice without the cleaning. Error: + # Condition "!p_keep_state && has_instances" is true. Returning: ERR_ALREADY_IN_USE + f = Callable() + g.clear() diff --git a/modules/gdscript/tests/scripts/analyzer/features/lambda_cyclic_ref_body.out b/modules/gdscript/tests/scripts/analyzer/features/lambda_cyclic_ref_body.out new file mode 100644 index 0000000000..6917fa7c2c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/lambda_cyclic_ref_body.out @@ -0,0 +1,5 @@ +GDTEST_OK +1 +2 +3 +33 -- cgit v1.2.3