summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/gdscript_analyzer.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-09-26 16:36:39 +0200
committerRémi Verschelde <rverschelde@gmail.com>2023-09-26 16:36:39 +0200
commit9b0b441cf386d4420b1ecc1ae3d39eff09dd2d23 (patch)
tree9fae7c9e5f0a3b385b0a2ac0772f8502ea54b41a /modules/gdscript/gdscript_analyzer.cpp
parent4410b0b0e164e6c7aa127dc22a47fc88497443f7 (diff)
parent4ce27301d3baec04f8259db9a3bc5dacbe359304 (diff)
downloadredot-engine-9b0b441cf386d4420b1ecc1ae3d39eff09dd2d23.tar.gz
Merge pull request #82139 from dalexeev/gds-add-inferred-declaration-warning
GDScript: Add `INFERRED_DECLARATION` warning
Diffstat (limited to 'modules/gdscript/gdscript_analyzer.cpp')
-rw-r--r--modules/gdscript/gdscript_analyzer.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp
index 469c52dc9d..5b47ed1a46 100644
--- a/modules/gdscript/gdscript_analyzer.cpp
+++ b/modules/gdscript/gdscript_analyzer.cpp
@@ -1936,9 +1936,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
@@ -2152,7 +2157,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