summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorYuri Sizov <11782833+YuriSizov@users.noreply.github.com>2023-02-06 23:32:47 +0300
committerGitHub <noreply@github.com>2023-02-06 23:32:47 +0300
commit945207885b3cd97012215334e56fcd3139d25e9f (patch)
treee7338a4c7cecfada472d481fb244346a2fcbccd8 /core
parentc0edea37efeb4602d598e96617befe8f0938f798 (diff)
parent8400308ab30a2a32731d1c50b53f064edc8cf3ee (diff)
Merge pull request #72546 from vonagam/fix-typed-array-can-reference
GDScript: Fix can_reference check for typed arrays
Diffstat (limited to 'core')
-rw-r--r--core/variant/array.cpp3
-rw-r--r--core/variant/container_type_validate.h36
2 files changed, 17 insertions, 22 deletions
diff --git a/core/variant/array.cpp b/core/variant/array.cpp
index 2e1adb9167..d156c35343 100644
--- a/core/variant/array.cpp
+++ b/core/variant/array.cpp
@@ -225,6 +225,9 @@ void Array::assign(const Array &p_array) {
_p->array = p_array._p->array;
return;
}
+ if (typed.type == Variant::OBJECT || source_typed.type == Variant::OBJECT) {
+ ERR_FAIL_MSG(vformat(R"(Cannot assign contents of "Array[%s]" to "Array[%s]".)", Variant::get_type_name(source_typed.type), Variant::get_type_name(typed.type)));
+ }
Vector<Variant> array;
array.resize(size);
diff --git a/core/variant/container_type_validate.h b/core/variant/container_type_validate.h
index 796b66dc77..ad679db9d0 100644
--- a/core/variant/container_type_validate.h
+++ b/core/variant/container_type_validate.h
@@ -41,34 +41,26 @@ struct ContainerTypeValidate {
const char *where = "container";
_FORCE_INLINE_ bool can_reference(const ContainerTypeValidate &p_type) const {
- if (type == p_type.type) {
- if (type != Variant::OBJECT) {
- return true; //nothing else to check
- }
- } else {
+ if (type != p_type.type) {
return false;
+ } else if (type != Variant::OBJECT) {
+ return true;
}
- //both are object
-
- if ((class_name != StringName()) != (p_type.class_name != StringName())) {
- return false; //both need to have class or none
- }
-
- if (class_name != p_type.class_name) {
- if (!ClassDB::is_parent_class(p_type.class_name, class_name)) {
- return false;
- }
- }
-
- if (script.is_null() != p_type.script.is_null()) {
+ if (class_name == StringName()) {
+ return true;
+ } else if (p_type.class_name == StringName()) {
+ return false;
+ } else if (class_name != p_type.class_name && !ClassDB::is_parent_class(p_type.class_name, class_name)) {
return false;
}
- if (script != p_type.script) {
- if (!p_type.script->inherits_script(script)) {
- return false;
- }
+ if (script.is_null()) {
+ return true;
+ } else if (p_type.script.is_null()) {
+ return false;
+ } else if (script != p_type.script && !p_type.script->inherits_script(script)) {
+ return false;
}
return true;