diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-17 10:59:07 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-17 10:59:07 +0200 |
commit | 82b36cccc7b99df18314c12df3815d168621352a (patch) | |
tree | 69d65563fda46f5fb3aadc539208e8749bf00f52 /modules/gdscript/gdscript_analyzer.cpp | |
parent | 01eb81ba481317e0112caea16aae60c419af480c (diff) | |
parent | f9048fcd7d2bee9cc0a23a76269c52d637b6a5bf (diff) | |
download | redot-engine-82b36cccc7b99df18314c12df3815d168621352a.tar.gz |
Merge pull request #90756 from vnen/gdscript-warning-enum-without-default
GDScript: Warn when enum variable has no default
Diffstat (limited to 'modules/gdscript/gdscript_analyzer.cpp')
-rw-r--r-- | modules/gdscript/gdscript_analyzer.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index b198338ff0..cd19887d82 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -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 |