Skip to content

Commit f6c7b00

Browse files
committed
Merge pull request #94635 from dalexeev/gds-fix-false-positive-enum-without-default
GDScript: Fix false positive cases of `ENUM_VARIABLE_WITHOUT_DEFAULT`
2 parents ad1955a + 638148a commit f6c7b00

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

modules/gdscript/gdscript_analyzer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1967,8 +1967,8 @@ void GDScriptAnalyzer::resolve_assignable(GDScriptParser::AssignableNode *p_assi
19671967
}
19681968

19691969
#ifdef DEBUG_ENABLED
1970+
const bool is_parameter = p_assignable->type == GDScriptParser::Node::PARAMETER;
19701971
if (!has_specified_type) {
1971-
const bool is_parameter = p_assignable->type == GDScriptParser::Node::PARAMETER;
19721972
const String declaration_type = is_constant ? "Constant" : (is_parameter ? "Parameter" : "Variable");
19731973
if (p_assignable->infer_datatype || is_constant) {
19741974
// Do not produce the `INFERRED_DECLARATION` warning on type import because there is no way to specify the true type.
@@ -1980,7 +1980,7 @@ void GDScriptAnalyzer::resolve_assignable(GDScriptParser::AssignableNode *p_assi
19801980
} else {
19811981
parser->push_warning(p_assignable, GDScriptWarning::UNTYPED_DECLARATION, declaration_type, p_assignable->identifier->name);
19821982
}
1983-
} else if (specified_type.kind == GDScriptParser::DataType::ENUM && p_assignable->initializer == nullptr) {
1983+
} else if (!is_parameter && specified_type.kind == GDScriptParser::DataType::ENUM && p_assignable->initializer == nullptr) {
19841984
// Warn about enum variables without default value. Unless the enum defines the "0" value, then it's fine.
19851985
bool has_zero_value = false;
19861986
for (const KeyValue<StringName, int64_t> &kv : specified_type.enum_values) {

modules/gdscript/tests/scripts/analyzer/warnings/enum_without_default_value.gd

+14
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,17 @@ var has_no_zero: HasNoZero # Warning, because there is no `0` in the enum.
77
func test():
88
print(has_zero)
99
print(has_no_zero)
10+
11+
12+
# GH-94634. A parameter is either mandatory or has a default value.
13+
func test_no_exec(param: HasNoZero) -> void:
14+
print(param)
15+
16+
# Loop iterator always has a value.
17+
for i: HasNoZero in HasNoZero.values():
18+
print(i)
19+
20+
match param:
21+
# Pattern bind always has a value.
22+
var x:
23+
print(x)

0 commit comments

Comments
 (0)