Merge pull request #72546 from vonagam/fix-typed-array-can-reference
GDScript: Fix can_reference check for typed arrays
This commit is contained in:
commit
945207885b
|
@ -225,6 +225,9 @@ void Array::assign(const Array &p_array) {
|
||||||
_p->array = p_array._p->array;
|
_p->array = p_array._p->array;
|
||||||
return;
|
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;
|
Vector<Variant> array;
|
||||||
array.resize(size);
|
array.resize(size);
|
||||||
|
|
|
@ -41,36 +41,28 @@ struct ContainerTypeValidate {
|
||||||
const char *where = "container";
|
const char *where = "container";
|
||||||
|
|
||||||
_FORCE_INLINE_ bool can_reference(const ContainerTypeValidate &p_type) const {
|
_FORCE_INLINE_ bool can_reference(const ContainerTypeValidate &p_type) const {
|
||||||
if (type == p_type.type) {
|
if (type != p_type.type) {
|
||||||
if (type != Variant::OBJECT) {
|
return false;
|
||||||
return true; //nothing else to check
|
} else if (type != Variant::OBJECT) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//both are object
|
if (script.is_null()) {
|
||||||
|
return true;
|
||||||
if ((class_name != StringName()) != (p_type.class_name != StringName())) {
|
} else if (p_type.script.is_null()) {
|
||||||
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;
|
return false;
|
||||||
}
|
} else if (script != p_type.script && !p_type.script->inherits_script(script)) {
|
||||||
}
|
|
||||||
|
|
||||||
if (script.is_null() != p_type.script.is_null()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (script != p_type.script) {
|
|
||||||
if (!p_type.script->inherits_script(script)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -201,4 +201,10 @@ func test():
|
||||||
assert(typed_enums.get_typed_builtin() == TYPE_INT)
|
assert(typed_enums.get_typed_builtin() == TYPE_INT)
|
||||||
|
|
||||||
|
|
||||||
|
var a := A.new()
|
||||||
|
var typed_natives: Array[RefCounted] = [a]
|
||||||
|
var typed_scripts = Array(typed_natives, TYPE_OBJECT, "RefCounted", A)
|
||||||
|
assert(typed_scripts[0] == a)
|
||||||
|
|
||||||
|
|
||||||
print('ok')
|
print('ok')
|
||||||
|
|
Loading…
Reference in New Issue