1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

GDScript: Add INFERRED_DECLARATION warning

This commit is contained in:
Danil Alexeev
2023-09-22 20:57:24 +03:00
parent fe5b1c8d49
commit 4ce27301d3
5 changed files with 22 additions and 5 deletions

View File

@@ -1932,9 +1932,14 @@ void GDScriptAnalyzer::resolve_assignable(GDScriptParser::AssignableNode *p_assi
}
#ifdef DEBUG_ENABLED
if (!has_specified_type && !p_assignable->infer_datatype && !is_constant) {
if (!has_specified_type) {
const bool is_parameter = p_assignable->type == GDScriptParser::Node::PARAMETER;
parser->push_warning(p_assignable, GDScriptWarning::UNTYPED_DECLARATION, is_parameter ? "Parameter" : "Variable", p_assignable->identifier->name);
const String declaration_type = is_constant ? "Constant" : (is_parameter ? "Parameter" : "Variable");
if (p_assignable->infer_datatype || is_constant) {
parser->push_warning(p_assignable, GDScriptWarning::INFERRED_DECLARATION, declaration_type, p_assignable->identifier->name);
} else {
parser->push_warning(p_assignable, GDScriptWarning::UNTYPED_DECLARATION, declaration_type, p_assignable->identifier->name);
}
}
#endif
@@ -2148,7 +2153,9 @@ void GDScriptAnalyzer::resolve_for(GDScriptParser::ForNode *p_for) {
} else {
p_for->variable->set_datatype(variable_type);
#ifdef DEBUG_ENABLED
if (!variable_type.is_hard_type()) {
if (variable_type.is_hard_type()) {
parser->push_warning(p_for->variable, GDScriptWarning::INFERRED_DECLARATION, R"("for" iterator variable)", p_for->variable->name);
} else {
parser->push_warning(p_for->variable, GDScriptWarning::UNTYPED_DECLARATION, R"("for" iterator variable)", p_for->variable->name);
}
#endif