From 653a8b113a9677e534fa7061f39c7f56b3ed3663 Mon Sep 17 00:00:00 2001 From: PreslavPetrov Date: Sat, 4 May 2024 18:41:01 +0100 Subject: [PATCH] Register the export info correctly when a global class script is used as the variable type for Node --- modules/gdscript/gdscript_parser.cpp | 36 +++++++++++++------ .../parser/features/export_variable.gd | 6 ++++ .../parser/features/export_variable.notest.gd | 2 ++ .../parser/features/export_variable.out | 4 +++ 4 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 modules/gdscript/tests/scripts/parser/features/export_variable.notest.gd diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 9a4c92f601d..771ccf47b75 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -4315,39 +4315,55 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node return false; } break; - case GDScriptParser::DataType::CLASS: + case GDScriptParser::DataType::CLASS: { + StringName class_name; + if (export_type.class_type) { + class_name = export_type.class_type->get_global_name(); + } + if (class_name == StringName()) { + push_error(R"(Script export type must be a global class.)", p_annotation); + return false; + } if (ClassDB::is_parent_class(export_type.native_type, SNAME("Resource"))) { variable->export_info.type = Variant::OBJECT; variable->export_info.hint = PROPERTY_HINT_RESOURCE_TYPE; - variable->export_info.hint_string = export_type.to_string(); + variable->export_info.hint_string = class_name; } else if (ClassDB::is_parent_class(export_type.native_type, SNAME("Node"))) { variable->export_info.type = Variant::OBJECT; variable->export_info.hint = PROPERTY_HINT_NODE_TYPE; - variable->export_info.hint_string = export_type.to_string(); + variable->export_info.hint_string = class_name; } else { push_error(R"(Export type can only be built-in, a resource, a node, or an enum.)", p_annotation); return false; } + } break; - break; case GDScriptParser::DataType::SCRIPT: { StringName class_name; - StringName native_base; if (export_type.script_type.is_valid()) { - class_name = export_type.script_type->get_language()->get_global_class_name(export_type.script_type->get_path()); - native_base = export_type.script_type->get_instance_base_type(); + class_name = export_type.script_type->get_global_name(); } if (class_name == StringName()) { Ref