summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules/gdscript/gdscript_analyzer.cpp12
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/ctor_as_callable.gd10
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/ctor_as_callable.out3
3 files changed, 24 insertions, 1 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp
index e3d3c44dd1..6e1ecefba3 100644
--- a/modules/gdscript/gdscript_analyzer.cpp
+++ b/modules/gdscript/gdscript_analyzer.cpp
@@ -3366,7 +3366,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod
base = *p_base;
}
- const StringName &name = p_identifier->name;
+ StringName name = p_identifier->name;
if (base.kind == GDScriptParser::DataType::ENUM) {
if (base.is_meta_type) {
@@ -3461,12 +3461,18 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod
get_class_node_current_scope_classes(base_class, &script_classes);
}
+ bool is_constructor = base.is_meta_type && p_identifier->name == SNAME("new");
+
for (GDScriptParser::ClassNode *script_class : script_classes) {
if (p_base == nullptr && script_class->identifier && script_class->identifier->name == name) {
reduce_identifier_from_base_set_class(p_identifier, script_class->get_datatype());
return;
}
+ if (is_constructor) {
+ name = "_init";
+ }
+
if (script_class->has_member(name)) {
resolve_class_member(script_class, name, p_identifier);
@@ -3545,6 +3551,10 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod
const StringName &native = base.native_type;
if (class_exists(native)) {
+ if (is_constructor) {
+ name = "_init";
+ }
+
MethodInfo method_info;
if (ClassDB::has_property(native, name)) {
StringName getter_name = ClassDB::get_property_getter(native, name);
diff --git a/modules/gdscript/tests/scripts/runtime/features/ctor_as_callable.gd b/modules/gdscript/tests/scripts/runtime/features/ctor_as_callable.gd
new file mode 100644
index 0000000000..515efbc9ce
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/ctor_as_callable.gd
@@ -0,0 +1,10 @@
+# https://github.com/godotengine/godot/issues/70319
+
+class InnerClass:
+ pass
+
+func test():
+ var inner_ctor : Callable = InnerClass.new
+ print(inner_ctor)
+ var native_ctor : Callable = Node.new
+ print(native_ctor)
diff --git a/modules/gdscript/tests/scripts/runtime/features/ctor_as_callable.out b/modules/gdscript/tests/scripts/runtime/features/ctor_as_callable.out
new file mode 100644
index 0000000000..527e3e8f84
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/ctor_as_callable.out
@@ -0,0 +1,3 @@
+GDTEST_OK
+GDScript::new
+GDScriptNativeClass::new