summaryrefslogtreecommitdiff
path: root/modules/gdscript/gdscript_analyzer.cpp
diff options
context:
space:
mode:
authorrune-scape <allie.smith.epic@gmail.com>2022-12-12 07:35:55 -0500
committerrune-scape <allie.smith.epic@gmail.com>2022-12-15 14:56:23 -0500
commite1c63fee86a0f9682988258618fd992f431c5ec0 (patch)
tree4c255e4bbcbacdebd8349371ccdf3b59cffcef49 /modules/gdscript/gdscript_analyzer.cpp
parent47ef0549ee490bca066ac00587076f123d973a55 (diff)
GDScript: Fix built-in script and other `find_class` bugs
Diffstat (limited to 'modules/gdscript/gdscript_analyzer.cpp')
-rw-r--r--modules/gdscript/gdscript_analyzer.cpp40
1 files changed, 15 insertions, 25 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp
index 9ec53b2b66..597735c55a 100644
--- a/modules/gdscript/gdscript_analyzer.cpp
+++ b/modules/gdscript/gdscript_analyzer.cpp
@@ -3993,37 +3993,27 @@ GDScriptParser::DataType GDScriptAnalyzer::type_from_variant(const Variant &p_va
result.kind = GDScriptParser::DataType::CLASS;
// This might be an inner class, so we want to get the parser for the root.
// But still get the inner class from that tree.
- GDScript *current = gds.ptr();
- List<StringName> class_chain;
- while (current->_owner) {
- // Push to front so it's in reverse.
- class_chain.push_front(current->name);
- current = current->_owner;
- }
-
- Ref<GDScriptParserRef> ref = get_parser_for(current->get_path());
+ String script_path = gds->get_script_path();
+ Ref<GDScriptParserRef> ref = get_parser_for(script_path);
if (ref.is_null()) {
- push_error("Could not find script in path.", p_source);
+ push_error(vformat(R"(Could not find script "%s".)", script_path), p_source);
GDScriptParser::DataType error_type;
error_type.kind = GDScriptParser::DataType::VARIANT;
return error_type;
}
- ref->raise_status(GDScriptParserRef::INHERITANCE_SOLVED);
-
- GDScriptParser::ClassNode *found = ref->get_parser()->head;
-
- for (const StringName &E : class_chain) {
- if (!found->has_member(E)) {
- return GDScriptParser::DataType();
- }
-
- if (found->get_member(E).type != GDScriptParser::ClassNode::Member::CLASS) {
- return GDScriptParser::DataType();
+ Error err = ref->raise_status(GDScriptParserRef::INHERITANCE_SOLVED);
+ GDScriptParser::ClassNode *found = nullptr;
+ if (err == OK) {
+ found = ref->get_parser()->find_class(gds->fully_qualified_name);
+ if (found != nullptr) {
+ err = resolve_class_inheritance(found, p_source);
}
-
- resolve_class_member(found, E, p_source);
-
- found = found->get_member(E).m_class;
+ }
+ if (err || found == nullptr) {
+ push_error(vformat(R"(Could not resolve script "%s".)", script_path), p_source);
+ GDScriptParser::DataType error_type;
+ error_type.kind = GDScriptParser::DataType::VARIANT;
+ return error_type;
}
result = found->get_datatype();