From f3bf75fbb4edf5d73cdedaf196fdcd358e031c82 Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Thu, 1 Jun 2023 21:46:37 +0300 Subject: GDScript: Reset local variables on exit from block --- .../features/reset_local_var_on exit_block.gd | 10 ++++++++ .../features/reset_local_var_on exit_block.out | 3 +++ .../reset_unassigned_variables_in_loops.gd | 28 ++++++++++++++++++++++ .../reset_unassigned_variables_in_loops.out | 14 +++++++++++ 4 files changed, 55 insertions(+) create mode 100644 modules/gdscript/tests/scripts/runtime/features/reset_local_var_on exit_block.gd create mode 100644 modules/gdscript/tests/scripts/runtime/features/reset_local_var_on exit_block.out create mode 100644 modules/gdscript/tests/scripts/runtime/features/reset_unassigned_variables_in_loops.gd create mode 100644 modules/gdscript/tests/scripts/runtime/features/reset_unassigned_variables_in_loops.out (limited to 'modules/gdscript/tests/scripts') diff --git a/modules/gdscript/tests/scripts/runtime/features/reset_local_var_on exit_block.gd b/modules/gdscript/tests/scripts/runtime/features/reset_local_var_on exit_block.gd new file mode 100644 index 0000000000..c774ebf83c --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/reset_local_var_on exit_block.gd @@ -0,0 +1,10 @@ +# GH-77666 + +func test(): + var ref := RefCounted.new() + print(ref.get_reference_count()) + + if true: + var _temp := ref + + print(ref.get_reference_count()) diff --git a/modules/gdscript/tests/scripts/runtime/features/reset_local_var_on exit_block.out b/modules/gdscript/tests/scripts/runtime/features/reset_local_var_on exit_block.out new file mode 100644 index 0000000000..04b4638adf --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/reset_local_var_on exit_block.out @@ -0,0 +1,3 @@ +GDTEST_OK +1 +1 diff --git a/modules/gdscript/tests/scripts/runtime/features/reset_unassigned_variables_in_loops.gd b/modules/gdscript/tests/scripts/runtime/features/reset_unassigned_variables_in_loops.gd new file mode 100644 index 0000000000..c45f8dce48 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/reset_unassigned_variables_in_loops.gd @@ -0,0 +1,28 @@ +# GH-56223, GH-76569 + +func test(): + for i in 3: + var a + if true: + var b + if true: + var c + prints("Begin:", i, a, b, c) + a = 1 + b = 1 + c = 1 + prints("End:", i, a, b, c) + print("===") + var j := 0 + while j < 3: + var a + if true: + var b + if true: + var c + prints("Begin:", j, a, b, c) + a = 1 + b = 1 + c = 1 + prints("End:", j, a, b, c) + j += 1 diff --git a/modules/gdscript/tests/scripts/runtime/features/reset_unassigned_variables_in_loops.out b/modules/gdscript/tests/scripts/runtime/features/reset_unassigned_variables_in_loops.out new file mode 100644 index 0000000000..7eddcbf903 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/reset_unassigned_variables_in_loops.out @@ -0,0 +1,14 @@ +GDTEST_OK +Begin: 0 +End: 0 1 1 1 +Begin: 1 +End: 1 1 1 1 +Begin: 2 +End: 2 1 1 1 +=== +Begin: 0 +End: 0 1 1 1 +Begin: 1 +End: 1 1 1 1 +Begin: 2 +End: 2 1 1 1 -- cgit v1.2.3