You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
GDScript: Don't warn on unassigned for builtin-typed variables
If the type of a variable is a built-in Variant type, then it will automatically be assigned a default value based on the type. This means that the explicit initialization may be unnecessary. Thus this commit removes the warning in such case. This also changes the meaning of the unassigned warning to happen when the variable is used before being assigned, not when it has zero assignments.
This commit is contained in:
@@ -2769,10 +2769,6 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_assignment(ExpressionNode
|
||||
return parse_expression(false); // Return the following expression.
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
VariableNode *source_variable = nullptr;
|
||||
#endif
|
||||
|
||||
switch (p_previous_operand->type) {
|
||||
case Node::IDENTIFIER: {
|
||||
#ifdef DEBUG_ENABLED
|
||||
@@ -2781,8 +2777,6 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_assignment(ExpressionNode
|
||||
IdentifierNode *id = static_cast<IdentifierNode *>(p_previous_operand);
|
||||
switch (id->source) {
|
||||
case IdentifierNode::LOCAL_VARIABLE:
|
||||
|
||||
source_variable = id->variable_source;
|
||||
id->variable_source->usages--;
|
||||
break;
|
||||
case IdentifierNode::LOCAL_CONSTANT:
|
||||
@@ -2813,16 +2807,10 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_assignment(ExpressionNode
|
||||
update_extents(assignment);
|
||||
|
||||
make_completion_context(COMPLETION_ASSIGN, assignment);
|
||||
#ifdef DEBUG_ENABLED
|
||||
bool has_operator = true;
|
||||
#endif
|
||||
switch (previous.type) {
|
||||
case GDScriptTokenizer::Token::EQUAL:
|
||||
assignment->operation = AssignmentNode::OP_NONE;
|
||||
assignment->variant_op = Variant::OP_MAX;
|
||||
#ifdef DEBUG_ENABLED
|
||||
has_operator = false;
|
||||
#endif
|
||||
break;
|
||||
case GDScriptTokenizer::Token::PLUS_EQUAL:
|
||||
assignment->operation = AssignmentNode::OP_ADDITION;
|
||||
@@ -2878,16 +2866,6 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_assignment(ExpressionNode
|
||||
}
|
||||
complete_extents(assignment);
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
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
|
||||
|
||||
return assignment;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user