diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2023-06-21 21:51:05 +0200 |
|---|---|---|
| committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-06-21 21:51:05 +0200 |
| commit | faf3faa8c85a4bad00bc944a90e7f75e7ba5d519 (patch) | |
| tree | 073e7a143fff575d02432271c7a90cced98de8da /modules/gdscript/tests/scripts/runtime/features | |
| parent | 81a0199be46679213bd2a46cb75394c05eb52c30 (diff) | |
| parent | f3bf75fbb4edf5d73cdedaf196fdcd358e031c82 (diff) | |
| download | redot-engine-faf3faa8c85a4bad00bc944a90e7f75e7ba5d519.tar.gz | |
Merge pull request #77744 from dalexeev/gds-reset-block-locals-on-exit
GDScript: Reset local variables on exit from block
Diffstat (limited to 'modules/gdscript/tests/scripts/runtime/features')
4 files changed, 55 insertions, 0 deletions
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 <null> <null> <null> +End: 0 1 1 1 +Begin: 1 <null> <null> <null> +End: 1 1 1 1 +Begin: 2 <null> <null> <null> +End: 2 1 1 1 +=== +Begin: 0 <null> <null> <null> +End: 0 1 1 1 +Begin: 1 <null> <null> <null> +End: 1 1 1 1 +Begin: 2 <null> <null> <null> +End: 2 1 1 1 |
