2
0
Эх сурвалжийг харах

GDScript: Fix `native_type` is empty for autoload without script

Danil Alexeev 1 жил өмнө
parent
commit
6767de9b69

+ 6 - 2
modules/gdscript/gdscript_analyzer.cpp

@@ -386,6 +386,7 @@ Error GDScriptAnalyzer::resolve_class_inheritance(GDScriptParser::ClassNode *p_c
 	if (!p_class->extends_used) {
 	if (!p_class->extends_used) {
 		result.type_source = GDScriptParser::DataType::ANNOTATED_INFERRED;
 		result.type_source = GDScriptParser::DataType::ANNOTATED_INFERRED;
 		result.kind = GDScriptParser::DataType::NATIVE;
 		result.kind = GDScriptParser::DataType::NATIVE;
+		result.builtin_type = Variant::OBJECT;
 		result.native_type = SNAME("RefCounted");
 		result.native_type = SNAME("RefCounted");
 	} else {
 	} else {
 		result.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT;
 		result.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT;
@@ -464,6 +465,7 @@ Error GDScriptAnalyzer::resolve_class_inheritance(GDScriptParser::ClassNode *p_c
 					return ERR_PARSE_ERROR;
 					return ERR_PARSE_ERROR;
 				}
 				}
 				base.kind = GDScriptParser::DataType::NATIVE;
 				base.kind = GDScriptParser::DataType::NATIVE;
+				base.builtin_type = Variant::OBJECT;
 				base.native_type = name;
 				base.native_type = name;
 			} else {
 			} else {
 				// Look for other classes in script.
 				// Look for other classes in script.
@@ -3965,8 +3967,10 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_ident
 		if (autoload.is_singleton) {
 		if (autoload.is_singleton) {
 			// Singleton exists, so it's at least a Node.
 			// Singleton exists, so it's at least a Node.
 			GDScriptParser::DataType result;
 			GDScriptParser::DataType result;
-			result.kind = GDScriptParser::DataType::NATIVE;
 			result.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT;
 			result.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT;
+			result.kind = GDScriptParser::DataType::NATIVE;
+			result.builtin_type = Variant::OBJECT;
+			result.native_type = SNAME("Node");
 			if (ResourceLoader::get_resource_type(autoload.path) == "GDScript") {
 			if (ResourceLoader::get_resource_type(autoload.path) == "GDScript") {
 				Ref<GDScriptParserRef> singl_parser = get_parser_for(autoload.path);
 				Ref<GDScriptParserRef> singl_parser = get_parser_for(autoload.path);
 				if (singl_parser.is_valid()) {
 				if (singl_parser.is_valid()) {
@@ -4839,7 +4843,7 @@ GDScriptParser::DataType GDScriptAnalyzer::type_from_property(const PropertyInfo
 			} else if (class_exists(elem_type_name)) {
 			} else if (class_exists(elem_type_name)) {
 				elem_type.kind = GDScriptParser::DataType::NATIVE;
 				elem_type.kind = GDScriptParser::DataType::NATIVE;
 				elem_type.builtin_type = Variant::OBJECT;
 				elem_type.builtin_type = Variant::OBJECT;
-				elem_type.native_type = p_property.hint_string;
+				elem_type.native_type = elem_type_name;
 			} else if (ScriptServer::is_global_class(elem_type_name)) {
 			} else if (ScriptServer::is_global_class(elem_type_name)) {
 				// Just load this as it shouldn't be a GDScript.
 				// Just load this as it shouldn't be a GDScript.
 				Ref<Script> script = ResourceLoader::load(ScriptServer::get_global_class_path(elem_type_name));
 				Ref<Script> script = ResourceLoader::load(ScriptServer::get_global_class_path(elem_type_name));

+ 7 - 1
modules/gdscript/gdscript_editor.cpp

@@ -1122,6 +1122,7 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
 						base_type.script_type = base_script;
 						base_type.script_type = base_script;
 					} else {
 					} else {
 						base_type.kind = GDScriptParser::DataType::NATIVE;
 						base_type.kind = GDScriptParser::DataType::NATIVE;
+						base_type.builtin_type = Variant::OBJECT;
 						base_type.native_type = scr->get_instance_base_type();
 						base_type.native_type = scr->get_instance_base_type();
 					}
 					}
 				} else {
 				} else {
@@ -1626,6 +1627,7 @@ static bool _guess_expression_type(GDScriptParser::CompletionContext &p_context,
 									native_type.script_type = parent;
 									native_type.script_type = parent;
 								} else {
 								} else {
 									native_type.kind = GDScriptParser::DataType::NATIVE;
 									native_type.kind = GDScriptParser::DataType::NATIVE;
+									native_type.builtin_type = Variant::OBJECT;
 									native_type.native_type = native_type.script_type->get_instance_base_type();
 									native_type.native_type = native_type.script_type->get_instance_base_type();
 									if (!ClassDB::class_exists(native_type.native_type)) {
 									if (!ClassDB::class_exists(native_type.native_type)) {
 										native_type.kind = GDScriptParser::DataType::UNRESOLVED;
 										native_type.kind = GDScriptParser::DataType::UNRESOLVED;
@@ -2155,6 +2157,7 @@ static bool _guess_identifier_type(GDScriptParser::CompletionContext &p_context,
 	if (ClassDB::class_exists(p_identifier->name) && ClassDB::is_class_exposed(p_identifier->name)) {
 	if (ClassDB::class_exists(p_identifier->name) && ClassDB::is_class_exposed(p_identifier->name)) {
 		r_type.type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT;
 		r_type.type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT;
 		r_type.type.kind = GDScriptParser::DataType::NATIVE;
 		r_type.type.kind = GDScriptParser::DataType::NATIVE;
+		r_type.type.builtin_type = Variant::OBJECT;
 		r_type.type.native_type = p_identifier->name;
 		r_type.type.native_type = p_identifier->name;
 		r_type.type.is_constant = true;
 		r_type.type.is_constant = true;
 		if (Engine::get_singleton()->has_singleton(p_identifier->name)) {
 		if (Engine::get_singleton()->has_singleton(p_identifier->name)) {
@@ -2281,6 +2284,7 @@ static bool _guess_identifier_type_from_base(GDScriptParser::CompletionContext &
 						base_type.script_type = parent;
 						base_type.script_type = parent;
 					} else {
 					} else {
 						base_type.kind = GDScriptParser::DataType::NATIVE;
 						base_type.kind = GDScriptParser::DataType::NATIVE;
+						base_type.builtin_type = Variant::OBJECT;
 						base_type.native_type = scr->get_instance_base_type();
 						base_type.native_type = scr->get_instance_base_type();
 					}
 					}
 				} else {
 				} else {
@@ -2450,6 +2454,7 @@ static bool _guess_method_return_type_from_base(GDScriptParser::CompletionContex
 						base_type.script_type = base_script;
 						base_type.script_type = base_script;
 					} else {
 					} else {
 						base_type.kind = GDScriptParser::DataType::NATIVE;
 						base_type.kind = GDScriptParser::DataType::NATIVE;
+						base_type.builtin_type = Variant::OBJECT;
 						base_type.native_type = scr->get_instance_base_type();
 						base_type.native_type = scr->get_instance_base_type();
 					}
 					}
 				} else {
 				} else {
@@ -2705,8 +2710,8 @@ static bool _get_subscript_type(GDScriptParser::CompletionContext &p_context, co
 			}
 			}
 			r_base_type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT;
 			r_base_type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT;
 			r_base_type.kind = GDScriptParser::DataType::NATIVE;
 			r_base_type.kind = GDScriptParser::DataType::NATIVE;
-			r_base_type.native_type = node->get_class_name();
 			r_base_type.builtin_type = Variant::OBJECT;
 			r_base_type.builtin_type = Variant::OBJECT;
+			r_base_type.native_type = node->get_class_name();
 			return true;
 			return true;
 		}
 		}
 	}
 	}
@@ -3260,6 +3265,7 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co
 						base_type.script_type = base_script;
 						base_type.script_type = base_script;
 					} else {
 					} else {
 						base_type.kind = GDScriptParser::DataType::NATIVE;
 						base_type.kind = GDScriptParser::DataType::NATIVE;
+						base_type.builtin_type = Variant::OBJECT;
 						base_type.native_type = scr->get_instance_base_type();
 						base_type.native_type = scr->get_instance_base_type();
 					}
 					}
 				} else {
 				} else {