summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/tests/scripts
diff options
context:
space:
mode:
authorDanil Alexeev <danil@alexeev.xyz>2023-06-01 21:46:37 +0300
committerDanil Alexeev <danil@alexeev.xyz>2023-06-02 13:20:19 +0300
commitf3bf75fbb4edf5d73cdedaf196fdcd358e031c82 (patch)
treef9c41abd88579ada14440309299d54fff46b0078 /modules/gdscript/tests/scripts
parent621d68e4129e7e343ff21eb3a5f4e8c1d6bbf456 (diff)
downloadredot-engine-f3bf75fbb4edf5d73cdedaf196fdcd358e031c82.tar.gz
GDScript: Reset local variables on exit from block
Diffstat (limited to 'modules/gdscript/tests/scripts')
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/reset_local_var_on exit_block.gd10
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/reset_local_var_on exit_block.out3
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/reset_unassigned_variables_in_loops.gd28
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/reset_unassigned_variables_in_loops.out14
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