GDScript: Check `get_node()` shorthand in static functions
This commit is contained in:
parent
11ea4dc466
commit
0f27c4ad80
|
@ -3301,17 +3301,26 @@ void GDScriptAnalyzer::reduce_dictionary(GDScriptParser::DictionaryNode *p_dicti
|
||||||
|
|
||||||
void GDScriptAnalyzer::reduce_get_node(GDScriptParser::GetNodeNode *p_get_node) {
|
void GDScriptAnalyzer::reduce_get_node(GDScriptParser::GetNodeNode *p_get_node) {
|
||||||
GDScriptParser::DataType result;
|
GDScriptParser::DataType result;
|
||||||
result.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT;
|
result.kind = GDScriptParser::DataType::VARIANT;
|
||||||
result.kind = GDScriptParser::DataType::NATIVE;
|
|
||||||
result.native_type = SNAME("Node");
|
|
||||||
result.builtin_type = Variant::OBJECT;
|
|
||||||
|
|
||||||
if (!ClassDB::is_parent_class(parser->current_class->base_type.native_type, result.native_type)) {
|
if (!ClassDB::is_parent_class(parser->current_class->base_type.native_type, SNAME("Node"))) {
|
||||||
push_error(R"*(Cannot use shorthand "get_node()" notation ("$") on a class that isn't a node.)*", p_get_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 (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();
|
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);
|
p_get_node->set_datatype(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3035,10 +3035,8 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_get_node(ExpressionNode *p
|
||||||
if (previous.type == GDScriptTokenizer::Token::DOLLAR) {
|
if (previous.type == GDScriptTokenizer::Token::DOLLAR) {
|
||||||
// Detect initial slash, which will be handled in the loop if it matches.
|
// Detect initial slash, which will be handled in the loop if it matches.
|
||||||
match(GDScriptTokenizer::Token::SLASH);
|
match(GDScriptTokenizer::Token::SLASH);
|
||||||
#ifdef DEBUG_ENABLED
|
|
||||||
} else {
|
} else {
|
||||||
get_node->use_dollar = false;
|
get_node->use_dollar = false;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int context_argument = 0;
|
int context_argument = 0;
|
||||||
|
|
|
@ -848,9 +848,7 @@ public:
|
||||||
|
|
||||||
struct GetNodeNode : public ExpressionNode {
|
struct GetNodeNode : public ExpressionNode {
|
||||||
String full_path;
|
String full_path;
|
||||||
#ifdef DEBUG_ENABLED
|
|
||||||
bool use_dollar = true;
|
bool use_dollar = true;
|
||||||
#endif
|
|
||||||
|
|
||||||
GetNodeNode() {
|
GetNodeNode() {
|
||||||
type = GET_NODE;
|
type = GET_NODE;
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
# GH-75645
|
||||||
|
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
static func static_func():
|
||||||
|
var a = $Node
|
||||||
|
|
||||||
|
func test():
|
||||||
|
pass
|
|
@ -0,0 +1,2 @@
|
||||||
|
GDTEST_ANALYZER_ERROR
|
||||||
|
Cannot use shorthand "get_node()" notation ("$") in a static function.
|
Loading…
Reference in New Issue