summaryrefslogtreecommitdiff
path: root/modules/gdscript
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/gdscript_analyzer.cpp12
-rw-r--r--modules/gdscript/gdscript_cache.cpp32
-rw-r--r--modules/gdscript/gdscript_cache.h1
-rw-r--r--modules/gdscript/gdscript_warning.cpp2
-rw-r--r--modules/gdscript/tests/scripts/parser/warnings/return_value_discarded.out2
5 files changed, 46 insertions, 3 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp
index 42a944f631..584bb74e4f 100644
--- a/modules/gdscript/gdscript_analyzer.cpp
+++ b/modules/gdscript/gdscript_analyzer.cpp
@@ -3124,6 +3124,18 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_ident
result = type_from_metatype(singl_parser->get_parser()->head->get_datatype());
}
}
+ } else if (ResourceLoader::get_resource_type(autoload.path) == "PackedScene") {
+ Error err = OK;
+ Ref<GDScript> scr = GDScriptCache::get_packed_scene_script(autoload.path, err);
+ if (err == OK && scr.is_valid()) {
+ Ref<GDScriptParserRef> singl_parser = get_parser_for(scr->get_path());
+ if (singl_parser.is_valid()) {
+ err = singl_parser->raise_status(GDScriptParserRef::INTERFACE_SOLVED);
+ if (err == OK) {
+ result = type_from_metatype(singl_parser->get_parser()->head->get_datatype());
+ }
+ }
+ }
}
result.is_constant = true;
p_identifier->set_datatype(result);
diff --git a/modules/gdscript/gdscript_cache.cpp b/modules/gdscript/gdscript_cache.cpp
index add36591f3..f35318e4c6 100644
--- a/modules/gdscript/gdscript_cache.cpp
+++ b/modules/gdscript/gdscript_cache.cpp
@@ -342,7 +342,12 @@ Ref<PackedScene> GDScriptCache::get_packed_scene(const String &p_path, Error &r_
return singleton->packed_scene_cache[p_path];
}
- Ref<PackedScene> scene;
+ Ref<PackedScene> scene = ResourceCache::get_ref(p_path);
+ if (scene.is_valid()) {
+ singleton->packed_scene_cache[p_path] = scene;
+ singleton->packed_scene_dependencies[p_path].insert(p_owner);
+ return scene;
+ }
scene.instantiate();
r_error = OK;
@@ -360,6 +365,31 @@ Ref<PackedScene> GDScriptCache::get_packed_scene(const String &p_path, Error &r_
return scene;
}
+Ref<GDScript> GDScriptCache::get_packed_scene_script(const String &p_path, Error &r_error) {
+ r_error = OK;
+ Ref<PackedScene> scene = get_packed_scene(p_path, r_error);
+
+ if (r_error != OK) {
+ return Ref<GDScript>();
+ }
+
+ int node_count = scene->get_state()->get_node_count();
+ if (node_count == 0) {
+ return Ref<GDScript>();
+ }
+
+ const int ROOT_NODE = 0;
+ for (int i = 0; i < scene->get_state()->get_node_property_count(ROOT_NODE); i++) {
+ if (scene->get_state()->get_node_property_name(ROOT_NODE, i) != SNAME("script")) {
+ continue;
+ }
+
+ return scene->get_state()->get_node_property_value(ROOT_NODE, i);
+ }
+
+ return Ref<GDScript>();
+}
+
void GDScriptCache::clear_unreferenced_packed_scenes() {
if (singleton == nullptr) {
return;
diff --git a/modules/gdscript/gdscript_cache.h b/modules/gdscript/gdscript_cache.h
index 2195932aa3..0f9d87aa67 100644
--- a/modules/gdscript/gdscript_cache.h
+++ b/modules/gdscript/gdscript_cache.h
@@ -102,6 +102,7 @@ public:
static Error finish_compiling(const String &p_owner);
static Ref<PackedScene> get_packed_scene(const String &p_path, Error &r_error, const String &p_owner = "");
+ static Ref<GDScript> get_packed_scene_script(const String &p_path, Error &r_error);
static void clear_unreferenced_packed_scenes();
static bool is_destructing() {
diff --git a/modules/gdscript/gdscript_warning.cpp b/modules/gdscript/gdscript_warning.cpp
index a0c107aa53..2548d26e14 100644
--- a/modules/gdscript/gdscript_warning.cpp
+++ b/modules/gdscript/gdscript_warning.cpp
@@ -96,7 +96,7 @@ String GDScriptWarning::get_message() const {
} break;
case RETURN_VALUE_DISCARDED: {
CHECK_SYMBOLS(1);
- return "The function '" + symbols[0] + "()' returns a value, but this value is never used.";
+ return "The function '" + symbols[0] + "()' returns a value that will be discarded if not used.";
} break;
case PROPERTY_USED_AS_FUNCTION: {
CHECK_SYMBOLS(2);
diff --git a/modules/gdscript/tests/scripts/parser/warnings/return_value_discarded.out b/modules/gdscript/tests/scripts/parser/warnings/return_value_discarded.out
index 13f759dd46..e89bb9226f 100644
--- a/modules/gdscript/tests/scripts/parser/warnings/return_value_discarded.out
+++ b/modules/gdscript/tests/scripts/parser/warnings/return_value_discarded.out
@@ -2,4 +2,4 @@ GDTEST_OK
>> WARNING
>> Line: 6
>> RETURN_VALUE_DISCARDED
->> The function 'i_return_int()' returns a value, but this value is never used.
+>> The function 'i_return_int()' returns a value that will be discarded if not used.