summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/tests/scripts
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-06-14 09:23:32 +0200
committerRémi Verschelde <rverschelde@gmail.com>2023-06-14 09:23:32 +0200
commit8b62c52d1cf1bd38fdd379eeb8dd91644a42a70e (patch)
tree0accfaabd2f273470a3f03acbdf6e7aa815d121b /modules/gdscript/tests/scripts
parent0ebd2aea4576c2b15a15b2fde489e9124c69d3ff (diff)
parent8655d979a19bc2c295bd1c41c3fa0e9dba097a0c (diff)
downloadredot-engine-8b62c52d1cf1bd38fdd379eeb8dd91644a42a70e.tar.gz
Merge pull request #75419 from vonagam/fix-super-classes-in-array-literals
GDScript: Allow elements of a parent class in a typed array literal
Diffstat (limited to 'modules/gdscript/tests/scripts')
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/typed_array_usage.gd4
-rw-r--r--modules/gdscript/tests/scripts/runtime/errors/typed_array_assign_wrong_to_typed.gd7
-rw-r--r--modules/gdscript/tests/scripts/runtime/errors/typed_array_assign_wrong_to_typed.out7
3 files changed, 16 insertions, 2 deletions
diff --git a/modules/gdscript/tests/scripts/analyzer/features/typed_array_usage.gd b/modules/gdscript/tests/scripts/analyzer/features/typed_array_usage.gd
index 26542a9e2f..c4108f50de 100644
--- a/modules/gdscript/tests/scripts/analyzer/features/typed_array_usage.gd
+++ b/modules/gdscript/tests/scripts/analyzer/features/typed_array_usage.gd
@@ -116,8 +116,8 @@ func test():
assert(duplicated_floats.get_typed_builtin() == TYPE_FLOAT)
- var b_objects: Array[B] = [B.new(), null]
- assert(b_objects.size() == 2)
+ var b_objects: Array[B] = [B.new(), B.new() as A, null]
+ assert(b_objects.size() == 3)
assert(b_objects.get_typed_builtin() == TYPE_OBJECT)
assert(b_objects.get_typed_script() == B)
diff --git a/modules/gdscript/tests/scripts/runtime/errors/typed_array_assign_wrong_to_typed.gd b/modules/gdscript/tests/scripts/runtime/errors/typed_array_assign_wrong_to_typed.gd
new file mode 100644
index 0000000000..83ec6573df
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/errors/typed_array_assign_wrong_to_typed.gd
@@ -0,0 +1,7 @@
+class Foo: pass
+class Bar extends Foo: pass
+class Baz extends Foo: pass
+
+func test():
+ var typed: Array[Bar] = [Baz.new() as Foo]
+ print('not ok')
diff --git a/modules/gdscript/tests/scripts/runtime/errors/typed_array_assign_wrong_to_typed.out b/modules/gdscript/tests/scripts/runtime/errors/typed_array_assign_wrong_to_typed.out
new file mode 100644
index 0000000000..a300145266
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/errors/typed_array_assign_wrong_to_typed.out
@@ -0,0 +1,7 @@
+GDTEST_RUNTIME_ERROR
+>> ERROR
+>> on function: assign()
+>> core/variant/array.cpp
+>> 222
+>> Method/function failed.
+not ok