@@ -101,7 +101,6 @@ GDScriptParser::GDScriptParser() {
101101 register_annotation (MethodInfo (" @onready" ), AnnotationInfo::VARIABLE, &GDScriptParser::onready_annotation);
102102 // Export annotations.
103103 register_annotation (MethodInfo (" @export" ), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_NONE, Variant::NIL>);
104- register_annotation (MethodInfo (" @export_storage" ), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_NONE, Variant::NIL>);
105104 register_annotation (MethodInfo (" @export_enum" , PropertyInfo (Variant::STRING, " names" )), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_ENUM, Variant::NIL>, varray (), true );
106105 register_annotation (MethodInfo (" @export_file" , PropertyInfo (Variant::STRING, " filter" )), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_FILE, Variant::STRING>, varray (" " ), true );
107106 register_annotation (MethodInfo (" @export_dir" ), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_DIR, Variant::STRING>);
@@ -121,6 +120,7 @@ GDScriptParser::GDScriptParser() {
121120 register_annotation (MethodInfo (" @export_flags_3d_physics" ), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_LAYERS_3D_PHYSICS, Variant::INT>);
122121 register_annotation (MethodInfo (" @export_flags_3d_navigation" ), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_LAYERS_3D_NAVIGATION, Variant::INT>);
123122 register_annotation (MethodInfo (" @export_flags_avoidance" ), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_LAYERS_AVOIDANCE, Variant::INT>);
123+ register_annotation (MethodInfo (" @export_storage" ), AnnotationInfo::VARIABLE, &GDScriptParser::export_storage_annotation);
124124 register_annotation (MethodInfo (" @export_custom" , PropertyInfo (Variant::INT, " hint" , PROPERTY_HINT_NONE, " " , PROPERTY_USAGE_CLASS_IS_ENUM, " PropertyHint" ), PropertyInfo (Variant::STRING, " hint_string" ), PropertyInfo (Variant::INT, " usage" , PROPERTY_HINT_NONE, " " , PROPERTY_USAGE_CLASS_IS_BITFIELD, " PropertyUsageFlags" )), AnnotationInfo::VARIABLE, &GDScriptParser::export_custom_annotation, varray (PROPERTY_USAGE_DEFAULT));
125125 // Export grouping annotations.
126126 register_annotation (MethodInfo (" @export_category" , PropertyInfo (Variant::STRING, " name" )), AnnotationInfo::STANDALONE, &GDScriptParser::export_group_annotations<PROPERTY_USAGE_CATEGORY>);
@@ -4299,7 +4299,7 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node
42994299 case GDScriptParser::DataType::BUILTIN:
43004300 variable->export_info .type = export_type.builtin_type ;
43014301 variable->export_info .hint = PROPERTY_HINT_NONE;
4302- variable->export_info .hint_string = Variant::get_type_name (export_type. builtin_type );
4302+ variable->export_info .hint_string = String ( );
43034303 break ;
43044304 case GDScriptParser::DataType::NATIVE:
43054305 if (ClassDB::is_parent_class (export_type.native_type , SNAME (" Resource" ))) {
@@ -4400,12 +4400,6 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node
44004400 push_error (_get_annotation_error_string (p_annotation->name , expected_types, variable->get_datatype ()), p_annotation);
44014401 return false ;
44024402 }
4403- } else if (p_annotation->name == SNAME (" @export_storage" )) {
4404- use_default_variable_type_check = false ; // Can be applied to a variable of any type.
4405-
4406- // Save the info because the compiler uses export info for overwriting member info.
4407- variable->export_info = export_type.to_property_info (variable->identifier ->name );
4408- variable->export_info .usage |= PROPERTY_USAGE_STORAGE;
44094403 }
44104404
44114405 if (use_default_variable_type_check) {
@@ -4425,11 +4419,38 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node
44254419 if (variable->export_info .hint ) {
44264420 hint_prefix += " /" + itos (variable->export_info .hint );
44274421 }
4422+ variable->export_info .type = original_export_type_builtin;
44284423 variable->export_info .hint = PROPERTY_HINT_TYPE_STRING;
44294424 variable->export_info .hint_string = hint_prefix + " :" + variable->export_info .hint_string ;
4430- variable->export_info .type = original_export_type_builtin;
4425+ variable->export_info .usage = PROPERTY_USAGE_DEFAULT;
4426+ variable->export_info .class_name = StringName ();
4427+ }
4428+
4429+ return true ;
4430+ }
4431+
4432+ // For `@export_storage` and `@export_custom`, there is no need to check the variable type, argument values,
4433+ // or handle array exports in a special way, so they are implemented as separate methods.
4434+
4435+ bool GDScriptParser::export_storage_annotation (const AnnotationNode *p_annotation, Node *p_node, ClassNode *p_class) {
4436+ ERR_FAIL_COND_V_MSG (p_node->type != Node::VARIABLE, false , vformat (R"( "%s" annotation can only be applied to variables.)" , p_annotation->name ));
4437+
4438+ VariableNode *variable = static_cast <VariableNode *>(p_node);
4439+ if (variable->is_static ) {
4440+ push_error (vformat (R"( Annotation "%s" cannot be applied to a static variable.)" , p_annotation->name ), p_annotation);
4441+ return false ;
4442+ }
4443+ if (variable->exported ) {
4444+ push_error (vformat (R"( Annotation "%s" cannot be used with another "@export" annotation.)" , p_annotation->name ), p_annotation);
4445+ return false ;
44314446 }
44324447
4448+ variable->exported = true ;
4449+
4450+ // Save the info because the compiler uses export info for overwriting member info.
4451+ variable->export_info = variable->get_datatype ().to_property_info (variable->identifier ->name );
4452+ variable->export_info .usage |= PROPERTY_USAGE_STORAGE;
4453+
44334454 return true ;
44344455}
44354456
@@ -4438,6 +4459,10 @@ bool GDScriptParser::export_custom_annotation(const AnnotationNode *p_annotation
44384459 ERR_FAIL_COND_V_MSG (p_annotation->resolved_arguments .size () < 2 , false , R"( Annotation "@export_custom" requires 2 arguments.)" );
44394460
44404461 VariableNode *variable = static_cast <VariableNode *>(p_node);
4462+ if (variable->is_static ) {
4463+ push_error (vformat (R"( Annotation "%s" cannot be applied to a static variable.)" , p_annotation->name ), p_annotation);
4464+ return false ;
4465+ }
44414466 if (variable->exported ) {
44424467 push_error (vformat (R"( Annotation "%s" cannot be used with another "@export" annotation.)" , p_annotation->name ), p_annotation);
44434468 return false ;
0 commit comments