Merge pull request #72925 from vonagam/fix-enum-typed-array-error

GDScript: Fix error about enum typed arrays
This commit is contained in:
Yuri Sizov 2023-02-17 16:47:50 +03:00 committed by GitHub
commit 6e0dd6beca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 10 deletions

View file

@ -4252,18 +4252,22 @@ Variant GDScriptAnalyzer::make_subscript_reduced_value(GDScriptParser::Subscript
Array GDScriptAnalyzer::make_array_from_element_datatype(const GDScriptParser::DataType &p_element_datatype, const GDScriptParser::Node *p_source_node) {
Array array;
Ref<Script> script_type = p_element_datatype.script_type;
if (p_element_datatype.kind == GDScriptParser::DataType::CLASS && script_type.is_null()) {
Error err = OK;
Ref<GDScript> scr = GDScriptCache::get_shallow_script(p_element_datatype.script_path, err);
if (err) {
push_error(vformat(R"(Error while getting cache for script "%s".)", p_element_datatype.script_path), p_source_node);
return array;
if (p_element_datatype.builtin_type == Variant::OBJECT) {
Ref<Script> script_type = p_element_datatype.script_type;
if (p_element_datatype.kind == GDScriptParser::DataType::CLASS && script_type.is_null()) {
Error err = OK;
Ref<GDScript> scr = GDScriptCache::get_shallow_script(p_element_datatype.script_path, err);
if (err) {
push_error(vformat(R"(Error while getting cache for script "%s".)", p_element_datatype.script_path), p_source_node);
return array;
}
script_type.reference_ptr(scr->find_class(p_element_datatype.class_type->fqcn));
}
script_type.reference_ptr(scr->find_class(p_element_datatype.class_type->fqcn));
}
array.set_typed(p_element_datatype.builtin_type, p_element_datatype.native_type, script_type);
array.set_typed(p_element_datatype.builtin_type, p_element_datatype.native_type, script_type);
} else {
array.set_typed(p_element_datatype.builtin_type, StringName(), Variant());
}
return array;
}

View file

@ -201,6 +201,10 @@ func test():
assert(str(typed_enums) == '[391]')
assert(typed_enums.get_typed_builtin() == TYPE_INT)
const const_enums: Array[E] = []
assert(const_enums.get_typed_builtin() == TYPE_INT)
assert(const_enums.get_typed_class_name() == &'')
var a := A.new()
var typed_natives: Array[RefCounted] = [a]