summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/tests
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript/tests')
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_call_arg.gd5
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_call_arg.out2
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_param.gd5
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/lambda_cyclic_ref_param.out2
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_before_declared.gd5
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_before_declared.out2
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_const.gd5
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_const.out2
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_type.gd5
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_type.out2
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/lambda_cyclic_ref_body.gd34
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/lambda_cyclic_ref_body.out5
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.gd41
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.notest.gd6
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.out11
15 files changed, 132 insertions, 0 deletions
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/errors/local_const_as_type_use_before_declared.gd b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_before_declared.gd
new file mode 100644
index 0000000000..7cdc14685f
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_before_declared.gd
@@ -0,0 +1,5 @@
+enum MyEnum {}
+
+func test():
+ var e: E
+ const E = MyEnum
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_before_declared.out b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_before_declared.out
new file mode 100644
index 0000000000..e1d5837f32
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_before_declared.out
@@ -0,0 +1,2 @@
+GDTEST_ANALYZER_ERROR
+Local constant "E" is not resolved at this point.
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_const.gd b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_const.gd
new file mode 100644
index 0000000000..68cf5efd8b
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_const.gd
@@ -0,0 +1,5 @@
+enum MyEnum {}
+
+func test():
+ var E = MyEnum
+ var e: E
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_const.out b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_const.out
new file mode 100644
index 0000000000..b1f4e7a2c8
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_const.out
@@ -0,0 +1,2 @@
+GDTEST_ANALYZER_ERROR
+Local variable "E" cannot be used as a type.
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_type.gd b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_type.gd
new file mode 100644
index 0000000000..ac446183cb
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_type.gd
@@ -0,0 +1,5 @@
+enum MyEnum {A}
+
+func test():
+ const E = MyEnum.A
+ var e: E
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_type.out b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_type.out
new file mode 100644
index 0000000000..c3c2c8ca2f
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/local_const_as_type_use_not_type.out
@@ -0,0 +1,2 @@
+GDTEST_ANALYZER_ERROR
+Local constant "E" is not a valid type.
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
diff --git a/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.gd b/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.gd
new file mode 100644
index 0000000000..90c7f893b1
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.gd
@@ -0,0 +1,41 @@
+class InnerClass:
+ enum InnerEnum {A = 2}
+ const INNER_CONST = "INNER_CONST"
+
+enum Enum {A = 1}
+
+const Other = preload("./local_const_as_type.notest.gd")
+
+func test():
+ const IC = InnerClass
+ const IE = IC.InnerEnum
+ const E = Enum
+ # Doesn't work in CI, but works in the editor. Looks like an unrelated bug. TODO: Investigate it.
+ # Error: Invalid call. Nonexistent function 'new' in base 'GDScript'.
+ var a1: IC = null # IC.new()
+ var a2: IE = IE.A
+ var a3: IC.InnerEnum = IE.A
+ var a4: E = E.A
+ print(a1.INNER_CONST)
+ print(a2)
+ print(a3)
+ print(a4)
+
+ const O = Other
+ const OV: Variant = Other # Removes metatype.
+ const OIC = O.InnerClass
+ const OIE = OIC.InnerEnum
+ const OE = O.Enum
+ var b: O = O.new()
+ @warning_ignore("unsafe_method_access")
+ var bv: OV = OV.new()
+ var b1: OIC = OIC.new()
+ var b2: OIE = OIE.A
+ var b3: O.InnerClass.InnerEnum = OIE.A
+ var b4: OE = OE.A
+ print(b.CONST)
+ print(bv.CONST)
+ print(b1.INNER_CONST)
+ print(b2)
+ print(b3)
+ print(b4)
diff --git a/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.notest.gd
new file mode 100644
index 0000000000..f16cdc18d8
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.notest.gd
@@ -0,0 +1,6 @@
+class InnerClass:
+ enum InnerEnum {A = 20}
+ const INNER_CONST = "OTHER_INNER_CONST"
+
+enum Enum {A = 10}
+const CONST = "OTHER_CONST"
diff --git a/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.out b/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.out
new file mode 100644
index 0000000000..b00024de2c
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/local_const_as_type.out
@@ -0,0 +1,11 @@
+GDTEST_OK
+INNER_CONST
+2
+2
+1
+OTHER_CONST
+OTHER_CONST
+OTHER_INNER_CONST
+20
+20
+10