Godot Engine – Multi-platform 2D and 3D game engine
GDScript: Move variable/parameter usage tracking to the analyzer
mattigu292239db6b54
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cppindex bab4aeee3de..f8decbaa4ae 100644--- a/modules/gdscript/gdscript_analyzer.cpp+++ b/modules/gdscript/gdscript_analyzer.cpp@@ -1772,20 +1772,10 @@ void GDScriptAnalyzer::resolve_function_signature(GDScriptParser::FunctionNode *int default_value_count = 0;#endif // TOOLS_ENABLED-#ifdef DEBUG_ENABLED- String function_visible_name = function_name;- if (function_name == StringName()) {- function_visible_name = p_is_lambda ? "<anonymous lambda>" : "<unknown function>";- }-#endif // DEBUG_ENABLED-for (int i = 0; i < p_function->parameters.size(); i++) {resolve_parameter(p_function->parameters[i]);method_info.arguments.push_back(p_function->parameters[i]->type_constraint.to_property_info(p_function->parameters[i]->identifier->name));#ifdef DEBUG_ENABLED- if (p_function->parameters[i]->usages == 0 && !String(p_function->parameters[i]->identifier->name).begins_with("_") && !p_function->is_abstract) {- parser->push_warning(p_function->parameters[i]->identifier, GDScriptWarning::UNUSED_PARAMETER, function_visible_name, p_function->parameters[i]->identifier->name);- }is_shadowing(p_function->parameters[i]->identifier, "function parameter", true);#endif // DEBUG_ENABLED@@ -1822,9 +1812,6 @@ void GDScriptAnalyzer::resolve_function_signature(GDScriptParser::FunctionNode *#endif}#ifdef DEBUG_ENABLED- if (p_function->rest_parameter->usages == 0 && !String(p_function->rest_parameter->identifier->name).begins_with("_") && !p_function->is_abstract) {- parser->push_warning(p_function->rest_parameter->identifier, GDScriptWarning::UNUSED_PARAMETER, function_visible_name, p_function->rest_parameter->identifier->name);- }is_shadowing(p_function->rest_parameter->identifier, "function parameter", true);#endif // DEBUG_ENABLED}@@ -1984,6 +1971,10 @@ void GDScriptAnalyzer::resolve_function_signature(GDScriptParser::FunctionNode *}#ifdef DEBUG_ENABLED+ String function_visible_name = function_name;+ if (function_name == StringName()) {+ function_visible_name = p_is_lambda ? "<anonymous lambda>" : "<unknown function>";+ }if (p_function->return_type == nullptr) {parser->push_warning(p_function->start_line, p_function->start_column, p_function->header_end_line, p_function->header_end_column, GDScriptWarning::UNTYPED_DECLARATION, "Function", function_visible_name);}@@ -2030,6 +2021,24 @@ void GDScriptAnalyzer::resolve_function_body(GDScriptParser::FunctionNode *p_funstatic_context = p_function->is_static;resolve_suite(p_function->body);+#ifdef DEBUG_ENABLED+ const StringName function_name = p_function->identifier != nullptr ? p_function->identifier->name : StringName();+ String function_visible_name = function_name;+ if (function_name == StringName()) {+ function_visible_name = p_is_lambda ? "<anonymous lambda>" : "<unknown function>";+ }++ for (const GDScriptParser::ParameterNode *const param : p_function->parameters) {+ if (param->usages == 0 && !String(param->identifier->name).begins_with("_")) {+ parser->push_warning(param->identifier, GDScriptWarning::UNUSED_PARAMETER, function_visible_name, param->identifier->name);+ }+ }++ if (p_function->is_vararg() && p_function->rest_parameter->usages == 0 && !String(p_function->rest_parameter->identifier->name).begins_with("_")) {+ parser->push_warning(p_function->rest_parameter->identifier, GDScriptWarning::UNUSED_PARAMETER, function_visible_name, p_function->rest_parameter->identifier->name);+ }++#endif //DEBUG_ENABLEDif (!p_function->return_type_constraint.is_hard_type() && p_function->body->suite_type.is_set()) {// Use the suite inferred type if return isn't explicitly set.@@ -2117,6 +2126,32 @@ void GDScriptAnalyzer::resolve_suite(GDScriptParser::SuiteNode *p_suite, bool p_p_suite->suite_type.type_source = GDScriptParser::DataType::INFERRED;}}+#ifdef DEBUG_ENABLED+ for (const GDScriptParser::SuiteNode::Local &local : p_suite->locals) {+ int usages = -1;+ GDScriptWarning::Code warning;+ const GDScriptParser::Node *node;++ switch (local.type) {+ case GDScriptParser::SuiteNode::Local::VARIABLE:+ usages = local.variable->usages;+ warning = GDScriptWarning::UNUSED_VARIABLE;+ node = local.variable;+ break;+ case GDScriptParser::SuiteNode::Local::CONSTANT:+ usages = local.constant->usages;+ warning = GDScriptWarning::UNUSED_LOCAL_CONSTANT;+ node = local.constant;+ break;+ default:+ continue;+ }+ if (usages == 0 && !String(local.name).begins_with("_")) {+ parser->push_warning(node, warning, local.name);+ }+ }++#endif // DEBUG_ENABLED}void GDScriptAnalyzer::resolve_assignable(GDScriptParser::AssignableNode *p_assignable, const char *p_kind) {@@ -2264,11 +2299,6 @@ void GDScriptAnalyzer::resolve_variable(GDScriptParser::VariableNode *p_variableresolve_assignable(p_variable, kind);#ifdef DEBUG_ENABLED- if (p_is_local) {- if (p_variable->usages == 0 && !String(p_variable->identifier->name).begins_with("_")) {- parser->push_warning(p_variable, GDScriptWarning::UNUSED_VARIABLE, p_variable->identifier->name);- }- }is_shadowing(p_variable->identifier, kind, p_is_local);#endif // DEBUG_ENABLED}@@ -2278,11 +2308,6 @@ void GDScriptAnalyzer::resolve_constant(GDScriptParser::ConstantNode *p_constantresolve_assignable(p_constant, kind);#ifdef DEBUG_ENABLED- if (p_is_local) {- if (p_constant->usages == 0 && !String(p_constant->identifier->name).begins_with("_")) {- parser->push_warning(p_constant, GDScriptWarning::UNUSED_LOCAL_CONSTANT, p_constant->identifier->name);- }- }is_shadowing(p_constant->identifier, kind, p_is_local);#endif // DEBUG_ENABLED}@@ -2471,6 +2496,16 @@ void GDScriptAnalyzer::resolve_match_branch(GDScriptParser::MatchBranchNode *p_m}resolve_suite(p_match_branch->block);++#ifdef DEBUG_ENABLED+ if (p_match_branch->patterns.size() == 1) {+ for (const KeyValue<StringName, GDScriptParser::IdentifierNode *> &E : p_match_branch->patterns[0]->binds) {+ if (E.value->usages == 0 && !String(E.value->name).begins_with("_")) {+ parser->push_warning(E.value, GDScriptWarning::UNUSED_VARIABLE, E.value->name);+ }+ }+ }+#endif // DEBUG_ENABLED}void GDScriptAnalyzer::resolve_match_pattern(GDScriptParser::PatternNode *p_match_pattern, GDScriptParser::ExpressionNode *p_match_test) {@@ -2516,9 +2551,6 @@ void GDScriptAnalyzer::resolve_match_pattern(GDScriptParser::PatternNode *p_matcp_match_pattern->bind->type_constraint = result;#ifdef DEBUG_ENABLEDis_shadowing(p_match_pattern->bind, "pattern bind", true);- if (p_match_pattern->bind->usages == 0 && !String(p_match_pattern->bind->name).begins_with("_")) {- parser->push_warning(p_match_pattern->bind, GDScriptWarning::UNUSED_VARIABLE, p_match_pattern->bind->name);- }#endif // DEBUG_ENABLEDbreak;case GDScriptParser::PatternNode::PT_ARRAY:@@ -2900,6 +2932,9 @@ void GDScriptAnalyzer::reduce_assignment(GDScriptParser::AssignmentNode *p_assigGDScriptParser::IdentifierNode *id = static_cast<GDScriptParser::IdentifierNode *>(p_assignment->assignee);if (id->source == GDScriptParser::IdentifierNode::LOCAL_VARIABLE && id->variable_source) {id->variable_source->assignments++;+ id->variable_source->usages--;+ } else if (id->source == GDScriptParser::IdentifierNode::FUNCTION_PARAMETER && id->parameter_source) {+ id->parameter_source->usages--;}}#endif // DEBUG_ENABLED@@ -4450,8 +4485,11 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_identcase GDScriptParser::IdentifierNode::FUNCTION_PARAMETER:p_identifier->type_constraint = p_identifier->parameter_source->type_constraint;found_source = true;+ p_identifier->parameter_source->usages++;break;case GDScriptParser::IdentifierNode::LOCAL_CONSTANT:+ p_identifier->constant_source->usages++;+ [[fallthrough]];case GDScriptParser::IdentifierNode::MEMBER_CONSTANT:p_identifier->type_constraint = p_identifier->constant_source->type_constraint;p_identifier->is_constant = true;@@ -4467,10 +4505,11 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_identbreak;case GDScriptParser::IdentifierNode::MEMBER_VARIABLE:mark_lambda_use_self();+ [[fallthrough]];+ case GDScriptParser::IdentifierNode::LOCAL_VARIABLE:p_identifier->variable_source->usages++;[[fallthrough]];case GDScriptParser::IdentifierNode::STATIC_VARIABLE:- case GDScriptParser::IdentifierNode::LOCAL_VARIABLE:p_identifier->type_constraint = p_identifier->variable_source->type_constraint;found_source = true;#ifdef DEBUG_ENABLED@@ -4482,12 +4521,14 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_identcase GDScriptParser::IdentifierNode::LOCAL_ITERATOR:p_identifier->type_constraint = p_identifier->bind_source->type_constraint;found_source = true;+ p_identifier->bind_source->usages++;break;case GDScriptParser::IdentifierNode::LOCAL_BIND: {GDScriptParser::DataType result = p_identifier->bind_source->type_constraint;result.is_constant = true;p_identifier->type_constraint = result;found_source = true;+ p_identifier->bind_source->usages++;} break;case GDScriptParser::IdentifierNode::UNDEFINED_SOURCE:case GDScriptParser::IdentifierNode::MEMBER_FUNCTION:diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cppindex 818312e7864..df43f966fb2 100644--- a/modules/gdscript/gdscript_parser.cpp+++ b/modules/gdscript/gdscript_parser.cpp@@ -2877,27 +2877,22 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_identifier(ExpressionNodecase SuiteNode::Local::CONSTANT:identifier->source = IdentifierNode::LOCAL_CONSTANT;identifier->constant_source = declaration.constant;- declaration.constant->usages++;break;case SuiteNode::Local::VARIABLE:identifier->source = IdentifierNode::LOCAL_VARIABLE;identifier->variable_source = declaration.variable;- declaration.variable->usages++;break;case SuiteNode::Local::PARAMETER:identifier->source = IdentifierNode::FUNCTION_PARAMETER;identifier->parameter_source = declaration.parameter;- declaration.parameter->usages++;break;case SuiteNode::Local::FOR_VARIABLE:identifier->source = IdentifierNode::LOCAL_ITERATOR;identifier->bind_source = declaration.bind;- declaration.bind->usages++;break;case SuiteNode::Local::PATTERN_BIND:identifier->source = IdentifierNode::LOCAL_BIND;identifier->bind_source = declaration.bind;- declaration.bind->usages++;break;case SuiteNode::Local::UNDEFINED:ERR_FAIL_V_MSG(nullptr, "Undefined local found.");@@ -3162,37 +3157,9 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_assignment(ExpressionNodereturn parse_expression(false); // Return the following expression.}- switch (p_previous_operand->type) {- case Node::IDENTIFIER: {-#ifdef DEBUG_ENABLED- // Get source to store assignment count.- // Also remove one usage since assignment isn't usage.- IdentifierNode *id = static_cast<IdentifierNode *>(p_previous_operand);- switch (id->source) {- case IdentifierNode::LOCAL_VARIABLE:- id->variable_source->usages--;- break;- case IdentifierNode::LOCAL_CONSTANT:- id->constant_source->usages--;- break;- case IdentifierNode::FUNCTION_PARAMETER:- id->parameter_source->usages--;- break;- case IdentifierNode::LOCAL_ITERATOR:- case IdentifierNode::LOCAL_BIND:- id->bind_source->usages--;- break;- default:- break;- }-#endif- } break;- case Node::SUBSCRIPT:- // Okay.- break;- default:- push_error(R"(Only identifier, attribute access, and subscription access can be used as assignment target.)");- return parse_expression(false); // Return the following expression.+ if (p_previous_operand->type != Node::SUBSCRIPT && p_previous_operand->type != Node::IDENTIFIER) {+ push_error(R"(Only identifier, attribute access, and subscription access can be used as assignment target.)");+ return parse_expression(false); // Return the following expression.}AssignmentNode *assignment = alloc_node<AssignmentNode>();diff --git a/modules/gdscript/tests/scripts/parser/warnings/shadowed_constant.gd b/modules/gdscript/tests/scripts/analyzer/warnings/shadowed_constant.gdsimilarity index 100%rename from modules/gdscript/tests/scripts/parser/warnings/shadowed_constant.gdrename to modules/gdscript/tests/scripts/analyzer/warnings/shadowed_constant.gddiff --git a/modules/gdscript/tests/scripts/parser/warnings/shadowed_constant.out b/modules/gdscript/tests/scripts/analyzer/warnings/shadowed_constant.outsimilarity index 100%rename from modules/gdscript/tests/scripts/parser/warnings/shadowed_constant.outrename to modules/gdscript/tests/scripts/analyzer/warnings/shadowed_constant.outindex 3f673141f1b..da7d4e2026f 100644--- a/modules/gdscript/tests/scripts/parser/warnings/shadowed_constant.out+++ b/modules/gdscript/tests/scripts/analyzer/warnings/shadowed_constant.out@@ -1,3 +1,3 @@GDTEST_OK-~~ WARNING at line 8: (UNUSED_LOCAL_CONSTANT) The local constant "TEST" is declared but never used in the block. If this is intended, prefix it with an underscore: "_TEST".~~ WARNING at line 8: (SHADOWED_VARIABLE) The local constant "TEST" is shadowing an already-declared constant at line 2 in the current class.+~~ WARNING at line 8: (UNUSED_LOCAL_CONSTANT) The local constant "TEST" is declared but never used in the block. If this is intended, prefix it with an underscore: "_TEST".diff --git a/modules/gdscript/tests/scripts/parser/warnings/shadowed_global_identifier.gd b/modules/gdscript/tests/scripts/analyzer/warnings/shadowed_global_identifier.gdsimilarity index 100%rename from modules/gdscript/tests/scripts/parser/warnings/shadowed_global_identifier.gdrename to modules/gdscript/tests/scripts/analyzer/warnings/shadowed_global_identifier.gddiff --git a/modules/gdscript/tests/scripts/parser/warnings/shadowed_global_identifier.out b/modules/gdscript/tests/scripts/analyzer/warnings/shadowed_global_identifier.outsimilarity index 100%rename from modules/gdscript/tests/scripts/parser/warnings/shadowed_global_identifier.outrename to modules/gdscript/tests/scripts/analyzer/warnings/shadowed_global_identifier.outindex 7c047b39415..a74529c1bb4 100644--- a/modules/gdscript/tests/scripts/parser/warnings/shadowed_global_identifier.out+++ b/modules/gdscript/tests/scripts/analyzer/warnings/shadowed_global_identifier.out@@ -1,3 +1,3 @@GDTEST_OK-~~ WARNING at line 2: (UNUSED_VARIABLE) The local variable "abs" is declared but never used in the block. If this is intended, prefix it with an underscore: "_abs".~~ WARNING at line 2: (SHADOWED_GLOBAL_IDENTIFIER) The variable "abs" has the same name as a built-in function.+~~ WARNING at line 2: (UNUSED_VARIABLE) The local variable "abs" is declared but never used in the block. If this is intended, prefix it with an underscore: "_abs".diff --git a/modules/gdscript/tests/scripts/parser/warnings/shadowed_variable_class.gd b/modules/gdscript/tests/scripts/analyzer/warnings/shadowed_variable_class.gdsimilarity index 100%rename from modules/gdscript/tests/scripts/parser/warnings/shadowed_variable_class.gdrename to modules/gdscript/tests/scripts/analyzer/warnings/shadowed_variable_class.gddiff --git a/modules/gdscript/tests/scripts/parser/warnings/shadowed_variable_class.out b/modules/gdscript/tests/scripts/analyzer/warnings/shadowed_variable_class.outsimilarity index 100%rename from modules/gdscript/tests/scripts/parser/warnings/shadowed_variable_class.outrename to modules/gdscript/tests/scripts/analyzer/warnings/shadowed_variable_class.outindex 1ee7378d482..a7539e79be9 100644--- a/modules/gdscript/tests/scripts/parser/warnings/shadowed_variable_class.out+++ b/modules/gdscript/tests/scripts/analyzer/warnings/shadowed_variable_class.out@@ -1,3 +1,3 @@GDTEST_OK-~~ WARNING at line 8: (UNUSED_VARIABLE) The local variable "foo" is declared but never used in the block. If this is intended, prefix it with an underscore: "_foo".~~ WARNING at line 8: (SHADOWED_VARIABLE) The local variable "foo" is shadowing an already-declared variable at line 1 in the current class.+~~ WARNING at line 8: (UNUSED_VARIABLE) The local variable "foo" is declared but never used in the block. If this is intended, prefix it with an underscore: "_foo".diff --git a/modules/gdscript/tests/scripts/parser/warnings/shadowed_variable_function.gd b/modules/gdscript/tests/scripts/analyzer/warnings/shadowed_variable_function.gdsimilarity index 100%rename from modules/gdscript/tests/scripts/parser/warnings/shadowed_variable_function.gdrename to modules/gdscript/tests/scripts/analyzer/warnings/shadowed_variable_function.gddiff --git a/modules/gdscript/tests/scripts/parser/warnings/shadowed_variable_function.out b/modules/gdscript/tests/scripts/analyzer/warnings/shadowed_variable_function.outsimilarity index 100%rename from modules/gdscript/tests/scripts/parser/warnings/shadowed_variable_function.outrename to modules/gdscript/tests/scripts/analyzer/warnings/shadowed_variable_function.outindex d9326eda28b..6b4b92ee120 100644--- a/modules/gdscript/tests/scripts/parser/warnings/shadowed_variable_function.out+++ b/modules/gdscript/tests/scripts/analyzer/warnings/shadowed_variable_function.out@@ -1,3 +1,3 @@GDTEST_OK-~~ WARNING at line 2: (UNUSED_VARIABLE) The local variable "test" is declared but never used in the block. If this is intended, prefix it with an underscore: "_test".~~ WARNING at line 2: (SHADOWED_VARIABLE) The local variable "test" is shadowing an already-declared function at line 1 in the current class.+~~ WARNING at line 2: (UNUSED_VARIABLE) The local variable "test" is declared but never used in the block. If this is intended, prefix it with an underscore: "_test".diff --git a/modules/gdscript/tests/scripts/parser/warnings/unused_argument.gd b/modules/gdscript/tests/scripts/analyzer/warnings/unused_argument.gdsimilarity index 100%rename from modules/gdscript/tests/scripts/parser/warnings/unused_argument.gdrename to modules/gdscript/tests/scripts/analyzer/warnings/unused_argument.gddiff --git a/modules/gdscript/tests/scripts/parser/warnings/unused_argument.out b/modules/gdscript/tests/scripts/analyzer/warnings/unused_argument.outsimilarity index 100%rename from modules/gdscript/tests/scripts/parser/warnings/unused_argument.outrename to modules/gdscript/tests/scripts/analyzer/warnings/unused_argument.outdiff --git a/modules/gdscript/tests/scripts/parser/warnings/unused_constant.gd b/modules/gdscript/tests/scripts/analyzer/warnings/unused_constant.gdsimilarity index 100%rename from modules/gdscript/tests/scripts/parser/warnings/unused_constant.gdrename to modules/gdscript/tests/scripts/analyzer/warnings/unused_constant.gddiff --git a/modules/gdscript/tests/scripts/parser/warnings/unused_constant.out b/modules/gdscript/tests/scripts/analyzer/warnings/unused_constant.outsimilarity index 100%rename from modules/gdscript/tests/scripts/parser/warnings/unused_constant.outrename to modules/gdscript/tests/scripts/analyzer/warnings/unused_constant.outdiff --git a/modules/gdscript/tests/scripts/analyzer/warnings/unused_identifiers_attribute_collision.gd b/modules/gdscript/tests/scripts/analyzer/warnings/unused_identifiers_attribute_collision.gdnew file mode 100644index 00000000000..e622467cf8c--- /dev/null+++ b/modules/gdscript/tests/scripts/analyzer/warnings/unused_identifiers_attribute_collision.gd@@ -0,0 +1,27 @@+class Test:+ var member := 0+++func test_variable():+ var bar := Test.new()+ var member = 0+ var _discard = bar.member++func test_constant():+ var bar := Test.new()+ const member := 0+ var _discard = bar.member++func test_parameter(member: int) -> void:+ var bar := Test.new()+ var _discard = bar.member++func test_pattern_bind():+ var bar := Test.new()+ match 0:+ var member:+ var _discard = bar.member+++func test():+ passdiff --git a/modules/gdscript/tests/scripts/analyzer/warnings/unused_identifiers_attribute_collision.out b/modules/gdscript/tests/scripts/analyzer/warnings/unused_identifiers_attribute_collision.outnew file mode 100644index 00000000000..04afdbf2d24--- /dev/null+++ b/modules/gdscript/tests/scripts/analyzer/warnings/unused_identifiers_attribute_collision.out@@ -0,0 +1,5 @@+GDTEST_OK+~~ WARNING at line 7: (UNUSED_VARIABLE) The local variable "member" is declared but never used in the block. If this is intended, prefix it with an underscore: "_member".+~~ WARNING at line 12: (UNUSED_LOCAL_CONSTANT) The local constant "member" is declared but never used in the block. If this is intended, prefix it with an underscore: "_member".+~~ WARNING at line 15: (UNUSED_PARAMETER) The parameter "member" is never used in the function "test_parameter()". If this is intended, prefix it with an underscore: "_member".+~~ WARNING at line 22: (UNUSED_VARIABLE) The local variable "member" is declared but never used in the block. If this is intended, prefix it with an underscore: "_member".diff --git a/modules/gdscript/tests/scripts/parser/warnings/unused_variable.gd b/modules/gdscript/tests/scripts/analyzer/warnings/unused_variable.gdsimilarity index 100%rename from modules/gdscript/tests/scripts/parser/warnings/unused_variable.gdrename to modules/gdscript/tests/scripts/analyzer/warnings/unused_variable.gddiff --git a/modules/gdscript/tests/scripts/parser/warnings/unused_variable.out b/modules/gdscript/tests/scripts/analyzer/warnings/unused_variable.outsimilarity index 100%rename from modules/gdscript/tests/scripts/parser/warnings/unused_variable.outrename to modules/gdscript/tests/scripts/analyzer/warnings/unused_variable.outdiff --git a/modules/gdscript/tests/scripts/analyzer/warnings/unused_variable_assigned.gd b/modules/gdscript/tests/scripts/analyzer/warnings/unused_variable_assigned.gdnew file mode 100644index 00000000000..ef9a5f239fb--- /dev/null+++ b/modules/gdscript/tests/scripts/analyzer/warnings/unused_variable_assigned.gd@@ -0,0 +1,18 @@+class Test:+ var member := 0++func param_test(param):+ param = 1++func param_member_test(param):+ param.member = 1++func test():+ var a = 1+ a = 2++ var b = 1+ b += 1++ var c = Test.new()+ c.member = 2diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/unused_variable_assigned.out b/modules/gdscript/tests/scripts/analyzer/warnings/unused_variable_assigned.outnew file mode 100644index 00000000000..8bb06b6c7f8--- /dev/null+++ b/modules/gdscript/tests/scripts/analyzer/warnings/unused_variable_assigned.out@@ -0,0 +1,4 @@+GDTEST_OK+~~ WARNING at line 4: (UNUSED_PARAMETER) The parameter "param" is never used in the function "param_test()". If this is intended, prefix it with an underscore: "_param".+~~ WARNING at line 11: (UNUSED_VARIABLE) The local variable "a" is declared but never used in the block. If this is intended, prefix it with an underscore: "_a".+~~ WARNING at line 14: (UNUSED_VARIABLE) The local variable "b" is declared but never used in the block. If this is intended, prefix it with an underscore: "_b".diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/unused_variable_pattern_guard.gd b/modules/gdscript/tests/scripts/analyzer/warnings/unused_variable_pattern_guard.gdnew file mode 100644index 00000000000..a949ebfb9dc--- /dev/null+++ b/modules/gdscript/tests/scripts/analyzer/warnings/unused_variable_pattern_guard.gd@@ -0,0 +1,16 @@+func test():+ match 0:+ var bind:+ pass++ match 0:+ var bind when 1 == 1:+ pass++ match 0:+ var bind when bind == 0:+ pass++ match 0:+ var bind when false:+ var _discard = binddiff --git a/modules/gdscript/tests/scripts/analyzer/warnings/unused_variable_pattern_guard.out b/modules/gdscript/tests/scripts/analyzer/warnings/unused_variable_pattern_guard.outnew file mode 100644index 00000000000..84104ecaa19--- /dev/null+++ b/modules/gdscript/tests/scripts/analyzer/warnings/unused_variable_pattern_guard.out@@ -0,0 +1,3 @@+GDTEST_OK+~~ WARNING at line 3: (UNUSED_VARIABLE) The local variable "bind" is declared but never used in the block. If this is intended, prefix it with an underscore: "_bind".+~~ WARNING at line 7: (UNUSED_VARIABLE) The local variable "bind" is declared but never used in the block. If this is intended, prefix it with an underscore: "_bind".diff --git a/modules/gdscript/tests/scripts/runtime/features/self_destruction.gd b/modules/gdscript/tests/scripts/runtime/features/self_destruction.gdindex 442335faeba..d73724b4761 100644--- a/modules/gdscript/tests/scripts/runtime/features/self_destruction.gd+++ b/modules/gdscript/tests/scripts/runtime/features/self_destruction.gd@@ -7,7 +7,7 @@ class MyObj:callable.call()var prop:- set(value):+ set(_value):callable.call()get:callable.call()