summaryrefslogtreecommitdiffstats
path: root/modules/gdscript
diff options
context:
space:
mode:
authorDanil Alexeev <danil@alexeev.xyz>2024-07-07 13:43:09 +0300
committerDanil Alexeev <danil@alexeev.xyz>2024-07-07 13:43:09 +0300
commitb4cb7ec2bbc2362f74f200606a9dbd04dd031407 (patch)
treeddf78c1effd163efdf44ba10976d372f91da1c58 /modules/gdscript
parentb97110cd307e4d78e20bfafe5de6c082194b2cd6 (diff)
downloadredot-engine-b4cb7ec2bbc2362f74f200606a9dbd04dd031407.tar.gz
GDScript: Fix implicit cast to typed array when passing parameter
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/gdscript_vm.cpp19
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/typed_array_implicit_cast_param.gd7
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/typed_array_implicit_cast_param.out2
3 files changed, 25 insertions, 3 deletions
diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp
index 5d1805696d..912367764b 100644
--- a/modules/gdscript/gdscript_vm.cpp
+++ b/modules/gdscript/gdscript_vm.cpp
@@ -550,9 +550,22 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
return _get_default_variant_for_data_type(return_type);
}
if (argument_types[i].kind == GDScriptDataType::BUILTIN) {
- Variant arg;
- Variant::construct(argument_types[i].builtin_type, arg, &p_args[i], 1, r_err);
- memnew_placement(&stack[i + 3], Variant(arg));
+ if (argument_types[i].builtin_type == Variant::ARRAY && argument_types[i].has_container_element_type(0)) {
+ const GDScriptDataType &arg_type = argument_types[i].container_element_types[0];
+ Array array(p_args[i]->operator Array(), arg_type.builtin_type, arg_type.native_type, arg_type.script_type);
+ memnew_placement(&stack[i + 3], Variant(array));
+ } else {
+ Variant variant;
+ Variant::construct(argument_types[i].builtin_type, variant, &p_args[i], 1, r_err);
+ if (unlikely(r_err.error)) {
+ r_err.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_err.argument = i;
+ r_err.expected = argument_types[i].builtin_type;
+ call_depth--;
+ return _get_default_variant_for_data_type(return_type);
+ }
+ memnew_placement(&stack[i + 3], Variant(variant));
+ }
} else {
memnew_placement(&stack[i + 3], Variant(*p_args[i]));
}
diff --git a/modules/gdscript/tests/scripts/runtime/features/typed_array_implicit_cast_param.gd b/modules/gdscript/tests/scripts/runtime/features/typed_array_implicit_cast_param.gd
new file mode 100644
index 0000000000..13f2c3b956
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/typed_array_implicit_cast_param.gd
@@ -0,0 +1,7 @@
+# GH-93990
+
+func test_param(array: Array[String]) -> void:
+ print(array.get_typed_builtin() == TYPE_STRING)
+
+func test() -> void:
+ test_param(PackedStringArray())
diff --git a/modules/gdscript/tests/scripts/runtime/features/typed_array_implicit_cast_param.out b/modules/gdscript/tests/scripts/runtime/features/typed_array_implicit_cast_param.out
new file mode 100644
index 0000000000..55482c2b52
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/typed_array_implicit_cast_param.out
@@ -0,0 +1,2 @@
+GDTEST_OK
+true