diff options
author | Danil Alexeev <danil@alexeev.xyz> | 2023-09-22 20:57:24 +0300 |
---|---|---|
committer | Danil Alexeev <danil@alexeev.xyz> | 2023-09-22 23:13:52 +0300 |
commit | 4ce27301d3baec04f8259db9a3bc5dacbe359304 (patch) | |
tree | 9c8331d23cf860da828fa921015adf9b5f79ddef /modules/gdscript/gdscript_analyzer.cpp | |
parent | fe5b1c8d49313d63fbe91cb7cdf463e10fb86afa (diff) | |
download | redot-engine-4ce27301d3baec04f8259db9a3bc5dacbe359304.tar.gz |
GDScript: Add `INFERRED_DECLARATION` warning
Diffstat (limited to 'modules/gdscript/gdscript_analyzer.cpp')
-rw-r--r-- | modules/gdscript/gdscript_analyzer.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 04c86d60a8..914f081e2b 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -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 |