mirror of
https://github.com/godotengine/godot.git
synced 2025-11-02 22:51:08 +00:00
Implement RETURN_VALUE_DISCARDED warning in GDscript
This commit is contained in:
parent
042e81f663
commit
be1e9acb7c
4 changed files with 18 additions and 8 deletions
|
|
@ -1041,7 +1041,7 @@ void GDScriptAnalyzer::resolve_class_body(GDScriptParser::ClassNode *p_class) {
|
|||
}
|
||||
}
|
||||
|
||||
void GDScriptAnalyzer::resolve_node(GDScriptParser::Node *p_node) {
|
||||
void GDScriptAnalyzer::resolve_node(GDScriptParser::Node *p_node, bool p_is_root) {
|
||||
ERR_FAIL_COND_MSG(p_node == nullptr, "Trying to resolve type of a null node.");
|
||||
|
||||
switch (p_node->type) {
|
||||
|
|
@ -1114,7 +1114,7 @@ void GDScriptAnalyzer::resolve_node(GDScriptParser::Node *p_node) {
|
|||
case GDScriptParser::Node::SUBSCRIPT:
|
||||
case GDScriptParser::Node::TERNARY_OPERATOR:
|
||||
case GDScriptParser::Node::UNARY_OPERATOR:
|
||||
reduce_expression(static_cast<GDScriptParser::ExpressionNode *>(p_node), true);
|
||||
reduce_expression(static_cast<GDScriptParser::ExpressionNode *>(p_node), p_is_root);
|
||||
break;
|
||||
case GDScriptParser::Node::BREAK:
|
||||
case GDScriptParser::Node::BREAKPOINT:
|
||||
|
|
@ -1411,7 +1411,7 @@ void GDScriptAnalyzer::resolve_for(GDScriptParser::ForNode *p_for) {
|
|||
variable_type.builtin_type = Variant::INT; // Can this ever be a float or something else?
|
||||
p_for->variable->set_datatype(variable_type);
|
||||
} else if (p_for->list) {
|
||||
resolve_node(p_for->list);
|
||||
resolve_node(p_for->list, false);
|
||||
if (p_for->list->datatype.has_container_element_type()) {
|
||||
variable_type = p_for->list->datatype.get_container_element_type();
|
||||
variable_type.type_source = GDScriptParser::DataType::ANNOTATED_INFERRED;
|
||||
|
|
@ -1439,7 +1439,7 @@ void GDScriptAnalyzer::resolve_for(GDScriptParser::ForNode *p_for) {
|
|||
}
|
||||
|
||||
void GDScriptAnalyzer::resolve_while(GDScriptParser::WhileNode *p_while) {
|
||||
resolve_node(p_while->condition);
|
||||
resolve_node(p_while->condition, false);
|
||||
|
||||
resolve_suite(p_while->loop);
|
||||
p_while->set_datatype(p_while->loop->get_datatype());
|
||||
|
|
@ -1824,7 +1824,7 @@ void GDScriptAnalyzer::reduce_expression(GDScriptParser::ExpressionNode *p_expre
|
|||
reduce_binary_op(static_cast<GDScriptParser::BinaryOpNode *>(p_expression));
|
||||
break;
|
||||
case GDScriptParser::Node::CALL:
|
||||
reduce_call(static_cast<GDScriptParser::CallNode *>(p_expression), p_is_root);
|
||||
reduce_call(static_cast<GDScriptParser::CallNode *>(p_expression), false, p_is_root);
|
||||
break;
|
||||
case GDScriptParser::Node::CAST:
|
||||
reduce_cast(static_cast<GDScriptParser::CastNode *>(p_expression));
|
||||
|
|
@ -2548,6 +2548,12 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a
|
|||
mark_lambda_use_self();
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (p_is_root && return_type.kind != GDScriptParser::DataType::UNRESOLVED && return_type.builtin_type != Variant::NIL) {
|
||||
parser->push_warning(p_call, GDScriptWarning::RETURN_VALUE_DISCARDED, p_call->function_name);
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
call_type = return_type;
|
||||
} else {
|
||||
bool found = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue