From 3fd30ed4ff7b5de01633e19b2769993b5b5d676b Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Thu, 30 May 2024 19:16:09 +0300 Subject: [PATCH] GDScript: Do not produce `INFERRED_DECLARATION` on type import --- modules/gdscript/gdscript_analyzer.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 7fe96146da79..1b09b50e2a36 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -1971,7 +1971,12 @@ void GDScriptAnalyzer::resolve_assignable(GDScriptParser::AssignableNode *p_assi const bool is_parameter = p_assignable->type == GDScriptParser::Node::PARAMETER; const String declaration_type = is_constant ? "Constant" : (is_parameter ? "Parameter" : "Variable"); if (p_assignable->infer_datatype || is_constant) { - parser->push_warning(p_assignable, GDScriptWarning::INFERRED_DECLARATION, declaration_type, p_assignable->identifier->name); + // Do not produce the `INFERRED_DECLARATION` warning on type import because there is no way to specify the true type. + // And removing the metatype makes it impossible to use the constant as a type hint (especially for enums). + const bool is_type_import = is_constant && p_assignable->initializer != nullptr && p_assignable->initializer->datatype.is_meta_type; + if (!is_type_import) { + parser->push_warning(p_assignable, GDScriptWarning::INFERRED_DECLARATION, declaration_type, p_assignable->identifier->name); + } } else { parser->push_warning(p_assignable, GDScriptWarning::UNTYPED_DECLARATION, declaration_type, p_assignable->identifier->name); }