Repository: godotengine/godot (language: cpp)

Issue:
Deep copy custom resource created in 4.4dev4 or newer throws Parser Error: Class hides a global script class
### Tested versions

- Reproducible in 4.4dev6, 4.3 stable, 4.2.2 stable, 4.0 stable, did not test older version

### System information

Godot v4.4.dev6 - Windows 10.0.22631 - Multi-window, 1 monitor - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4070 Laptop GPU (NVIDIA; 32.0.15.6636) - 13th Gen Intel(R) Core(TM) i9-13900H (20 threads)

### Issue description

Deep copying a custom resource ( cust_resource.duplicate(true) ) created in 4.4dev4 or newer results in Parser Error: Class "CustomResource" hides a global script class.

The same project and custom resource instance created in 4.4dev3 or older does not result in the error. Seems to be a regression related to https://github.com/godotengine/godot/issues/72119 fixed in https://github.com/godotengine/godot/pull/71142



### Steps to reproduce

As in MRP:
Create new custom resource with class_name (completely empty class is fine)
Perform a .duplicate(true) on custom resource

### Minimal reproduction project (MRP)

[mrp_resource_duplicate.zip](https://github.com/user-attachments/files/18049452/mrp_resource_duplicate.zip)



Discussion / hints:
For some reason some editor only metadata gets serialized to the file: `metadata/_custom_type_script`, this contains the same script as the `script` property. This metadata is not marked as never duplicate so it will result in the attempt to duplicate the script.
* See #91341.

CC @bjornmp @KoBeWi
Does anyone know a workaround for this?
You can manually edit the resource file using a text editor. Remove the `metadata/_custom_type_script` property, as long as you don't re-save the scene it should keep working. 

Fix patch:
diff --git a/core/object/object.cpp b/core/object/object.cpp
index 2f9d94d36a15..0be5aa284e5a 100644
--- a/core/object/object.cpp
+++ b/core/object/object.cpp
@@ -520,7 +520,13 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons
 		PropertyInfo pi = PropertyInfo(K.value.get_type(), "metadata/" + K.key.operator String());
 		if (K.value.get_type() == Variant::OBJECT) {
 			pi.hint = PROPERTY_HINT_RESOURCE_TYPE;
-			pi.hint_string = "Resource";
+			Object *obj = K.value;
+			if (Object::cast_to<Script>(obj)) {
+				pi.hint_string = "Script";
+				pi.usage |= PROPERTY_USAGE_NEVER_DUPLICATE;
+			} else {
+				pi.hint_string = "Resource";
+			}
 		}
 		p_list->push_back(pi);
 	}


Test patch: