You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
GDScript: Warn when enum variable has no default
The default will always be set to `0`, so if it's not a valid value in the enum, the warning is shown.
This commit is contained in:
@@ -1957,6 +1957,18 @@ void GDScriptAnalyzer::resolve_assignable(GDScriptParser::AssignableNode *p_assi
|
||||
} else {
|
||||
parser->push_warning(p_assignable, GDScriptWarning::UNTYPED_DECLARATION, declaration_type, p_assignable->identifier->name);
|
||||
}
|
||||
} else if (specified_type.kind == GDScriptParser::DataType::ENUM && p_assignable->initializer == nullptr) {
|
||||
// Warn about enum variables without default value. Unless the enum defines the "0" value, then it's fine.
|
||||
bool has_zero_value = false;
|
||||
for (const KeyValue<StringName, int64_t> &kv : specified_type.enum_values) {
|
||||
if (kv.value == 0) {
|
||||
has_zero_value = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!has_zero_value) {
|
||||
parser->push_warning(p_assignable, GDScriptWarning::ENUM_VARIABLE_WITHOUT_DEFAULT, p_assignable->identifier->name);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user