Merge pull request #59141 from Chaosus/gds_fix_default_arg_check

Fix default value count checking for inherited function
This commit is contained in:
Rémi Verschelde 2022-03-21 21:21:25 +01:00 committed by GitHub
commit 5e249d047f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1124,6 +1124,10 @@ void GDScriptAnalyzer::resolve_function_signature(GDScriptParser::FunctionNode *
GDScriptParser::FunctionNode *previous_function = parser->current_function;
parser->current_function = p_function;
#ifdef TOOLS_ENABLED
int default_value_count = 0;
#endif // TOOLS_ENABLED
for (int i = 0; i < p_function->parameters.size(); i++) {
resolve_parameter(p_function->parameters[i]);
#ifdef DEBUG_ENABLED
@ -1133,8 +1137,12 @@ void GDScriptAnalyzer::resolve_function_signature(GDScriptParser::FunctionNode *
is_shadowing(p_function->parameters[i]->identifier, "function parameter");
#endif // DEBUG_ENABLED
#ifdef TOOLS_ENABLED
if (p_function->parameters[i]->default_value && p_function->parameters[i]->default_value->is_constant) {
p_function->default_arg_values.push_back(p_function->parameters[i]->default_value->reduced_value);
if (p_function->parameters[i]->default_value) {
default_value_count++;
if (p_function->parameters[i]->default_value->is_constant) {
p_function->default_arg_values.push_back(p_function->parameters[i]->default_value->reduced_value);
}
}
#endif // TOOLS_ENABLED
}
@ -1169,7 +1177,7 @@ void GDScriptAnalyzer::resolve_function_signature(GDScriptParser::FunctionNode *
int par_count_diff = p_function->parameters.size() - parameters_types.size();
valid = valid && par_count_diff >= 0;
valid = valid && p_function->default_arg_values.size() >= default_par_count + par_count_diff;
valid = valid && default_value_count >= default_par_count + par_count_diff;
int i = 0;
for (const GDScriptParser::DataType &par_type : parameters_types) {
@ -1203,7 +1211,7 @@ void GDScriptAnalyzer::resolve_function_signature(GDScriptParser::FunctionNode *
push_error(vformat(R"(The function signature doesn't match the parent. Parent signature is "%s".)", parent_signature), p_function);
}
}
#endif
#endif // TOOLS_ENABLED
}
parser->current_function = previous_function;