From d6c799006ad9305fc4fca1574aff148e2529f8b6 Mon Sep 17 00:00:00 2001 From: George Marques Date: Wed, 6 Oct 2021 11:37:13 -0300 Subject: GDScript: Make all warnings enabled in test generation The test generation doesn't initialize the language (since it's already initialized in main), but it still needs the warning enabled so it matches the actual tests. --- modules/gdscript/tests/gdscript_test_runner.cpp | 13 ++++++------- .../analyzer/features/auto_inferred_type_dont_error.out | 4 ++++ 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'modules/gdscript/tests') diff --git a/modules/gdscript/tests/gdscript_test_runner.cpp b/modules/gdscript/tests/gdscript_test_runner.cpp index c383830c82..50c1f68440 100644 --- a/modules/gdscript/tests/gdscript_test_runner.cpp +++ b/modules/gdscript/tests/gdscript_test_runner.cpp @@ -133,13 +133,12 @@ GDScriptTestRunner::GDScriptTestRunner(const String &p_source_dir, bool p_init_l if (do_init_languages) { init_language(p_source_dir); - - // Enable all warnings for GDScript, so we can test them. - ProjectSettings::get_singleton()->set_setting("debug/gdscript/warnings/enable", true); - for (int i = 0; i < (int)GDScriptWarning::WARNING_MAX; i++) { - String warning = GDScriptWarning::get_name_from_code((GDScriptWarning::Code)i).to_lower(); - ProjectSettings::get_singleton()->set_setting("debug/gdscript/warnings/" + warning, true); - } + } + // Enable all warnings for GDScript, so we can test them. + ProjectSettings::get_singleton()->set_setting("debug/gdscript/warnings/enable", true); + for (int i = 0; i < (int)GDScriptWarning::WARNING_MAX; i++) { + String warning = GDScriptWarning::get_name_from_code((GDScriptWarning::Code)i).to_lower(); + ProjectSettings::get_singleton()->set_setting("debug/gdscript/warnings/" + warning, true); } // Enable printing to show results diff --git a/modules/gdscript/tests/scripts/analyzer/features/auto_inferred_type_dont_error.out b/modules/gdscript/tests/scripts/analyzer/features/auto_inferred_type_dont_error.out index 0e9f482af4..481016138a 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/auto_inferred_type_dont_error.out +++ b/modules/gdscript/tests/scripts/analyzer/features/auto_inferred_type_dont_error.out @@ -1,2 +1,6 @@ GDTEST_OK +>> WARNING +>> Line: 6 +>> UNSAFE_METHOD_ACCESS +>> The method 'free' is not present on the inferred type 'Variant' (but may be present on a subtype). Ok -- cgit v1.2.3 From 6bdb28f5e41d5e3eef866fde161fb5a259a6a11b Mon Sep 17 00:00:00 2001 From: George Marques Date: Wed, 6 Oct 2021 11:39:19 -0300 Subject: GDScript: Avoid hard errors on inferred types Since inference isn't always correct, they are now treated as unsafe instead of errors. This also removes inferred type when a variable is reassigned. Since it's not aware of branching, the types might become invalid in a later context. --- .../scripts/analyzer/features/class_inference_is_weak.gd | 11 +++++++++++ .../scripts/analyzer/features/class_inference_is_weak.out | 2 ++ .../scripts/analyzer/features/local_inference_is_weak.gd | 14 ++++++++++++++ .../scripts/analyzer/features/local_inference_is_weak.out | 2 ++ 4 files changed, 29 insertions(+) create mode 100644 modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.out create mode 100644 modules/gdscript/tests/scripts/analyzer/features/local_inference_is_weak.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/features/local_inference_is_weak.out (limited to 'modules/gdscript/tests') diff --git a/modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.gd b/modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.gd new file mode 100644 index 0000000000..630b20c282 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.gd @@ -0,0 +1,11 @@ +# https://github.com/godotengine/godot/issues/43503 + +var test_var = null + + +func test(): + print(test_var.x) + + +func _init(): + test_var = Vector3() diff --git a/modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.out b/modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.out new file mode 100644 index 0000000000..94e2ec2af8 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/class_inference_is_weak.out @@ -0,0 +1,2 @@ +GDTEST_OK +0 diff --git a/modules/gdscript/tests/scripts/analyzer/features/local_inference_is_weak.gd b/modules/gdscript/tests/scripts/analyzer/features/local_inference_is_weak.gd new file mode 100644 index 0000000000..b3784dffa3 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/local_inference_is_weak.gd @@ -0,0 +1,14 @@ +# https://github.com/godotengine/godot/issues/41064 +var x = true + +func test(): + var int_var: int = 0 + var dyn_var = 2 + + if x: + dyn_var = 5 + else: + dyn_var = Node.new() + + int_var = dyn_var + print(int_var) diff --git a/modules/gdscript/tests/scripts/analyzer/features/local_inference_is_weak.out b/modules/gdscript/tests/scripts/analyzer/features/local_inference_is_weak.out new file mode 100644 index 0000000000..952029f665 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/local_inference_is_weak.out @@ -0,0 +1,2 @@ +GDTEST_OK +5 -- cgit v1.2.3