GDScript: Removed spurious UNASSIGNED_VARIABLE warning for locals

Variable->assignment needs to be incremented when assigned a value.
Also fixed and improved unit test 'variable_declaration.gd'.
Fixes #52551
This commit is contained in:
ZuBsPaCe 2021-09-10 22:08:02 +02:00
parent 68563b5760
commit 1d1aa7a02f
3 changed files with 21 additions and 14 deletions

View file

@ -2369,8 +2369,12 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_assignment(ExpressionNode
}
#ifdef DEBUG_ENABLED
if (has_operator && source_variable != nullptr && source_variable->assignments == 0) {
push_warning(assignment, GDScriptWarning::UNASSIGNED_VARIABLE_OP_ASSIGN, source_variable->identifier->name);
if (source_variable != nullptr) {
if (has_operator && source_variable->assignments == 0) {
push_warning(assignment, GDScriptWarning::UNASSIGNED_VARIABLE_OP_ASSIGN, source_variable->identifier->name);
}
source_variable->assignments += 1;
}
#endif