Godot Engine – Multi-platform 2D and 3D game engine
GDScript: Add opt-in typing warnings to test runner, and remove duplicate `UNTYPED_DECLARATION` warning for rest parameters
Malcolm Anderson8f1881630568
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cppindex 60f029bf167..1262ca8ac9a 100644--- a/modules/gdscript/gdscript_analyzer.cpp+++ b/modules/gdscript/gdscript_analyzer.cpp@@ -1825,9 +1825,6 @@ void GDScriptAnalyzer::resolve_function_signature(GDScriptParser::FunctionNode *inferred_type.kind = GDScriptParser::DataType::BUILTIN;inferred_type.builtin_type = Variant::ARRAY;p_function->rest_parameter->type_constraint = inferred_type;-#ifdef DEBUG_ENABLED- parser->push_warning(p_function->rest_parameter, GDScriptWarning::UNTYPED_DECLARATION, "Parameter", p_function->rest_parameter->identifier->name);-#endif}#ifdef DEBUG_ENABLEDis_shadowing(p_function->rest_parameter->identifier, "function parameter", true);diff --git a/modules/gdscript/tests/gdscript_test_runner.cpp b/modules/gdscript/tests/gdscript_test_runner.cppindex 8fa20b1eb03..e6a22f6f026 100644--- a/modules/gdscript/tests/gdscript_test_runner.cpp+++ b/modules/gdscript/tests/gdscript_test_runner.cpp@@ -542,6 +542,18 @@ GDScriptTest::TestResult GDScriptTest::execute_test_code(bool p_is_generating) {ERR_FAIL_V_MSG(result, "\nCould not load source code for: '" + source_file + "'");}+#ifdef DEBUG_ENABLED+ // Allows us to enable the UNTYPED_DECLARATION and INFERRED_DECLARATION+ // warnings for specific tests by including a comment.+ const String sc = script->get_source_code();+ const String untyped_declaration_path = GDScriptWarning::get_setting_path_from_code(GDScriptWarning::UNTYPED_DECLARATION);+ const String inferred_declaration_path = GDScriptWarning::get_setting_path_from_code(GDScriptWarning::INFERRED_DECLARATION);++ ProjectSettings::get_singleton()->set_setting(untyped_declaration_path, (int)(sc.contains("# enable UNTYPED_DECLARATION") ? GDScriptWarning::WARN : GDScriptWarning::IGNORE));+ ProjectSettings::get_singleton()->set_setting(inferred_declaration_path, (int)(sc.contains("# enable INFERRED_DECLARATION") ? GDScriptWarning::WARN : GDScriptWarning::IGNORE));+ GDScriptParser::update_project_settings();+#endif // DEBUG_ENABLED+// Test parsing.GDScriptParser parser;if (tokenizer_mode == TOKENIZER_TEXT) {diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/untyped_declaration.gd b/modules/gdscript/tests/scripts/analyzer/warnings/untyped_declaration.gdnew file mode 100644index 00000000000..99659f4b7fd--- /dev/null+++ b/modules/gdscript/tests/scripts/analyzer/warnings/untyped_declaration.gd@@ -0,0 +1,10 @@+# enable UNTYPED_DECLARATION++func test() -> void:+ pass++func regular_function(_arg) -> void:+ pass++func vararg_function(..._var_args) -> void:+ passdiff --git a/modules/gdscript/tests/scripts/analyzer/warnings/untyped_declaration.out b/modules/gdscript/tests/scripts/analyzer/warnings/untyped_declaration.outnew file mode 100644index 00000000000..bf95d18c0ed--- /dev/null+++ b/modules/gdscript/tests/scripts/analyzer/warnings/untyped_declaration.out@@ -0,0 +1,3 @@+GDTEST_OK+~~ WARNING at line 6: (UNTYPED_DECLARATION) Parameter "_arg" has no static type.+~~ WARNING at line 9: (UNTYPED_DECLARATION) Parameter "_var_args" has no static type.