From 24b6edcd388836910655689fd6dd7bc3717ff256 Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Thu, 20 Jun 2024 13:05:29 +0300 Subject: [PATCH] GDScript: Fix non-global class export --- modules/gdscript/doc_classes/@GDScript.xml | 2 +- modules/gdscript/gdscript_parser.cpp | 110 ++++++++++-------- .../parser/features/export_variable.gd | 6 +- .../parser/features/export_variable.notest.gd | 2 - .../parser/features/export_variable.out | 6 +- .../features/export_variable_global.notest.gd | 2 + .../export_variable_unnamed.notest.gd | 1 + 7 files changed, 72 insertions(+), 57 deletions(-) delete mode 100644 modules/gdscript/tests/scripts/parser/features/export_variable.notest.gd create mode 100644 modules/gdscript/tests/scripts/parser/features/export_variable_global.notest.gd create mode 100644 modules/gdscript/tests/scripts/parser/features/export_variable_unnamed.notest.gd diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml index 1909ca5ab520..6e7ac0dec966 100644 --- a/modules/gdscript/doc_classes/@GDScript.xml +++ b/modules/gdscript/doc_classes/@GDScript.xml @@ -314,7 +314,7 @@ @export var image_array: Array[Image] @export var node_array: Array[Node] [/codeblock] - [b]Note:[/b] Custom resources and nodes must be registered as global classes using [code]class_name[/code]. + [b]Note:[/b] Custom resources and nodes should be registered as global classes using [code]class_name[/code], since the Inspector currently only supports global classes. Otherwise, a less specific type will be exported instead. [b]Note:[/b] Node export is only supported in [Node]-derived classes and has a number of other limitations. diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index f1a35c84b7f2..d0948e483132 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -4160,6 +4160,64 @@ static String _get_annotation_error_string(const StringName &p_annotation_name, return vformat(R"("%s" annotation requires a variable of type %s, but type "%s" was given instead.)", p_annotation_name, string, p_provided_type.to_string()); } +static StringName _find_narrowest_native_or_global_class(const GDScriptParser::DataType &p_type) { + switch (p_type.kind) { + case GDScriptParser::DataType::NATIVE: { + if (p_type.is_meta_type) { + return Object::get_class_static(); // `GDScriptNativeClass` is not an exposed class. + } + return p_type.native_type; + } break; + case GDScriptParser::DataType::SCRIPT: { + Ref