Skip to content

Commit 810fcc7

Browse files
baptrMikeSchulze
authored andcommitted
Fix gdscript analyzer error when instantiating EditorPlugins.
Editor code is not instantiable outside of the editor (https://github.com/godotengine/godot/blob/1d14c054a12dacdc193b589e4afb0ef319ee2aae/core/object/class_db.cpp#L369). This is fine for editor plugins and the like, but the GDScript analyzer balks at it, causing F5 runs to fail: godotengine#73525. Instead, we really just want to know if the type is abstract - so add a new ClassDB method to check that and nothing else. Update core/object/class_db.cpp Apply code review comments Co-Authored-By: Bryce <[email protected]>
1 parent e6448ca commit 810fcc7

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

core/object/class_db.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,21 @@ bool ClassDB::can_instantiate(const StringName &p_class) {
671671
return (!ti->disabled && ti->creation_func != nullptr && !(ti->gdextension && !ti->gdextension->create_instance));
672672
}
673673

674+
bool ClassDB::is_abstract(const StringName &p_class) {
675+
OBJTYPE_RLOCK;
676+
677+
ClassInfo *ti = classes.getptr(p_class);
678+
if (!ti) {
679+
if (!ScriptServer::is_global_class(p_class)) {
680+
ERR_FAIL_V_MSG(false, "Cannot get class '" + String(p_class) + "'.");
681+
}
682+
String path = ScriptServer::get_global_class_path(p_class);
683+
Ref<Script> scr = ResourceLoader::load(path);
684+
return scr.is_valid() && scr->is_valid() && scr->is_abstract();
685+
}
686+
return ti->creation_func == nullptr && (!ti->gdextension || ti->gdextension->create_instance == nullptr);
687+
}
688+
674689
bool ClassDB::is_virtual(const StringName &p_class) {
675690
OBJTYPE_RLOCK;
676691

core/object/class_db.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ class ClassDB {
287287
static bool class_exists(const StringName &p_class);
288288
static bool is_parent_class(const StringName &p_class, const StringName &p_inherits);
289289
static bool can_instantiate(const StringName &p_class);
290+
static bool is_abstract(const StringName &p_class);
290291
static bool is_virtual(const StringName &p_class);
291292
static Object *instantiate(const StringName &p_class);
292293
static Object *instantiate_no_placeholders(const StringName &p_class);

modules/gdscript/gdscript_analyzer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5180,7 +5180,7 @@ bool GDScriptAnalyzer::get_function_signature(GDScriptParser::Node *p_source, bo
51805180
if (!class_exists(base_native)) {
51815181
push_error(vformat("Native class %s used in script doesn't exist or isn't exposed.", base_native), p_source);
51825182
return false;
5183-
} else if (p_is_constructor && !ClassDB::can_instantiate(base_native)) {
5183+
} else if (p_is_constructor && ClassDB::is_abstract(base_native)) {
51845184
if (p_base_type.kind == GDScriptParser::DataType::CLASS) {
51855185
push_error(vformat(R"(Class "%s" cannot be constructed as it is based on abstract native class "%s".)", p_base_type.class_type->fqcn.get_file(), base_native), p_source);
51865186
} else if (p_base_type.kind == GDScriptParser::DataType::SCRIPT) {

0 commit comments

Comments
 (0)