summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/tests/scripts/analyzer/warnings
diff options
context:
space:
mode:
authorYuri Sizov <yuris@humnom.net>2023-07-31 21:01:36 +0200
committerYuri Sizov <yuris@humnom.net>2023-07-31 21:01:36 +0200
commit3de7dd902c3b491b92cad822eb1ce7018001c24b (patch)
tree29ac72747d9bb8ac089ad7a05842676861e97901 /modules/gdscript/tests/scripts/analyzer/warnings
parent8b12849fef2059421583e4e5bf2a27f654d8ab42 (diff)
parentd53fc92b4c6b5e4484e8f0bfff6ac55163dde3fb (diff)
downloadredot-engine-3de7dd902c3b491b92cad822eb1ce7018001c24b.tar.gz
Merge pull request #79880 from dalexeev/gds-fix-id-shadowing-below
GDScript: Fix bug with identifier shadowed below in current scope
Diffstat (limited to 'modules/gdscript/tests/scripts/analyzer/warnings')
-rw-r--r--modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_declaration.gd6
-rw-r--r--modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_declaration.out7
-rw-r--r--modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage.gd6
-rw-r--r--modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage.out11
-rw-r--r--modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_initializer.gd6
-rw-r--r--modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_initializer.out15
-rw-r--r--modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_loop.gd7
-rw-r--r--modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_loop.out15
8 files changed, 73 insertions, 0 deletions
diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_declaration.gd b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_declaration.gd
new file mode 100644
index 0000000000..3178f8d496
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_declaration.gd
@@ -0,0 +1,6 @@
+func test():
+ if true:
+ var a = 1
+ print(a)
+ var a = 2
+ print(a)
diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_declaration.out b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_declaration.out
new file mode 100644
index 0000000000..7365072ea7
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_declaration.out
@@ -0,0 +1,7 @@
+GDTEST_OK
+>> WARNING
+>> Line: 3
+>> CONFUSABLE_LOCAL_DECLARATION
+>> The variable "a" is declared below in the parent block.
+1
+2
diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage.gd b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage.gd
new file mode 100644
index 0000000000..4462c067bc
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage.gd
@@ -0,0 +1,6 @@
+var a = 1
+
+func test():
+ print(a)
+ var a = 2
+ print(a)
diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage.out b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage.out
new file mode 100644
index 0000000000..0e0d607831
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage.out
@@ -0,0 +1,11 @@
+GDTEST_OK
+>> WARNING
+>> Line: 4
+>> CONFUSABLE_LOCAL_USAGE
+>> The identifier "a" will be shadowed below in the block.
+>> WARNING
+>> Line: 5
+>> SHADOWED_VARIABLE
+>> The local variable "a" is shadowing an already-declared variable at line 1.
+1
+2
diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_initializer.gd b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_initializer.gd
new file mode 100644
index 0000000000..eef8eb66e6
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_initializer.gd
@@ -0,0 +1,6 @@
+var a = 1
+
+func test():
+ print(a)
+ var a = a + 1
+ print(a)
diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_initializer.out b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_initializer.out
new file mode 100644
index 0000000000..228a510490
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_initializer.out
@@ -0,0 +1,15 @@
+GDTEST_OK
+>> WARNING
+>> Line: 4
+>> CONFUSABLE_LOCAL_USAGE
+>> The identifier "a" will be shadowed below in the block.
+>> WARNING
+>> Line: 5
+>> CONFUSABLE_LOCAL_USAGE
+>> The identifier "a" will be shadowed below in the block.
+>> WARNING
+>> Line: 5
+>> SHADOWED_VARIABLE
+>> The local variable "a" is shadowing an already-declared variable at line 1.
+1
+2
diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_loop.gd b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_loop.gd
new file mode 100644
index 0000000000..1f207f27ac
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_loop.gd
@@ -0,0 +1,7 @@
+var a = 1
+
+func test():
+ for _i in 3:
+ print(a)
+ var a = 2
+ print(a)
diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_loop.out b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_loop.out
new file mode 100644
index 0000000000..0d20e9f7a0
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_loop.out
@@ -0,0 +1,15 @@
+GDTEST_OK
+>> WARNING
+>> Line: 5
+>> CONFUSABLE_LOCAL_USAGE
+>> The identifier "a" will be shadowed below in the block.
+>> WARNING
+>> Line: 6
+>> SHADOWED_VARIABLE
+>> The local variable "a" is shadowing an already-declared variable at line 1.
+1
+2
+1
+2
+1
+2