Skip to content

Commit fe5d567

Browse files
committed
Merge pull request godotengine#93942 from MikeSchulze/73525
Fix GDScript analyzer error when instantiating EditorPlugins.
2 parents 1b49d63 + 810fcc7 commit fe5d567

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
@@ -683,6 +683,21 @@ bool ClassDB::can_instantiate(const StringName &p_class) {
683683
return (!ti->disabled && ti->creation_func != nullptr && !(ti->gdextension && !ti->gdextension->create_instance));
684684
}
685685

686+
bool ClassDB::is_abstract(const StringName &p_class) {
687+
OBJTYPE_RLOCK;
688+
689+
ClassInfo *ti = classes.getptr(p_class);
690+
if (!ti) {
691+
if (!ScriptServer::is_global_class(p_class)) {
692+
ERR_FAIL_V_MSG(false, "Cannot get class '" + String(p_class) + "'.");
693+
}
694+
String path = ScriptServer::get_global_class_path(p_class);
695+
Ref<Script> scr = ResourceLoader::load(path);
696+
return scr.is_valid() && scr->is_valid() && scr->is_abstract();
697+
}
698+
return ti->creation_func == nullptr && (!ti->gdextension || ti->gdextension->create_instance == nullptr);
699+
}
700+
686701
bool ClassDB::is_virtual(const StringName &p_class) {
687702
OBJTYPE_RLOCK;
688703

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)