|
@@ -3301,17 +3301,26 @@ void GDScriptAnalyzer::reduce_dictionary(GDScriptParser::DictionaryNode *p_dicti
|
|
|
|
|
|
void GDScriptAnalyzer::reduce_get_node(GDScriptParser::GetNodeNode *p_get_node) {
|
|
|
GDScriptParser::DataType result;
|
|
|
- result.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT;
|
|
|
- result.kind = GDScriptParser::DataType::NATIVE;
|
|
|
- result.native_type = SNAME("Node");
|
|
|
- result.builtin_type = Variant::OBJECT;
|
|
|
+ result.kind = GDScriptParser::DataType::VARIANT;
|
|
|
+
|
|
|
+ if (!ClassDB::is_parent_class(parser->current_class->base_type.native_type, SNAME("Node"))) {
|
|
|
+ push_error(vformat(R"*(Cannot use shorthand "get_node()" notation ("%c") on a class that isn't a node.)*", p_get_node->use_dollar ? '$' : '%'), p_get_node);
|
|
|
+ p_get_node->set_datatype(result);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (!ClassDB::is_parent_class(parser->current_class->base_type.native_type, result.native_type)) {
|
|
|
- push_error(R"*(Cannot use shorthand "get_node()" notation ("$") on a class that isn't a node.)*", p_get_node);
|
|
|
+ if (static_context) {
|
|
|
+ push_error(vformat(R"*(Cannot use shorthand "get_node()" notation ("%c") in a static function.)*", p_get_node->use_dollar ? '$' : '%'), p_get_node);
|
|
|
+ p_get_node->set_datatype(result);
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
mark_lambda_use_self();
|
|
|
|
|
|
+ result.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT;
|
|
|
+ result.kind = GDScriptParser::DataType::NATIVE;
|
|
|
+ result.builtin_type = Variant::OBJECT;
|
|
|
+ result.native_type = SNAME("Node");
|
|
|
p_get_node->set_datatype(result);
|
|
|
}
|
|
|
|