From c0eeb32e38fbd4f582f7a2726e6535614e507205 Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Wed, 15 Mar 2023 22:11:02 +0300 Subject: [PATCH] GDScript: Fix false positive `REDUNDANT_AWAIT` warning --- modules/gdscript/gdscript_analyzer.cpp | 2 +- .../features/warning_ignore_annotation.gd | 2 +- .../analyzer/warnings/redundant_await.gd | 53 +++++++++++++++++++ .../analyzer/warnings/redundant_await.out | 37 +++++++++++++ .../features/await_without_coroutine.gd | 2 +- 5 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 modules/gdscript/tests/scripts/analyzer/warnings/redundant_await.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/warnings/redundant_await.out diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 38d5ae6b77c..c233d518012 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -2548,7 +2548,7 @@ void GDScriptAnalyzer::reduce_await(GDScriptParser::AwaitNode *p_await) { #ifdef DEBUG_ENABLED GDScriptParser::DataType to_await_type = p_await->to_await->get_datatype(); - if (!(to_await_type.has_no_type() || to_await_type.is_coroutine || to_await_type.builtin_type == Variant::SIGNAL)) { + if (!to_await_type.is_coroutine && !to_await_type.is_variant() && to_await_type.builtin_type != Variant::SIGNAL) { parser->push_warning(p_await, GDScriptWarning::REDUNDANT_AWAIT); } #endif diff --git a/modules/gdscript/tests/scripts/analyzer/features/warning_ignore_annotation.gd b/modules/gdscript/tests/scripts/analyzer/features/warning_ignore_annotation.gd index 4c02fd4b0da..292db30bcd4 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/warning_ignore_annotation.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/warning_ignore_annotation.gd @@ -11,5 +11,5 @@ func test(): print("done") -func regular_func(): +func regular_func() -> int: return 0 diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/redundant_await.gd b/modules/gdscript/tests/scripts/analyzer/warnings/redundant_await.gd new file mode 100644 index 00000000000..f8844d66a77 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/redundant_await.gd @@ -0,0 +1,53 @@ +signal my_signal() + +# CI cannot test async things. +func test_signals(): + await my_signal + var t: Signal = my_signal + await t + +func coroutine() -> void: + @warning_ignore("redundant_await") + await 0 + +func not_coroutine_variant(): + pass + +func not_coroutine_void() -> void: + pass + +func test(): + const CONST_NULL = null + var var_null = null + var var_int: int = 1 + var var_variant: Variant = 1 + var var_array: Array = [1] + + await CONST_NULL + await var_null + await var_int + await var_variant + await var_array[0] + + await coroutine + await coroutine() + await coroutine.call() + await self.coroutine() + await call(&"coroutine") + + await not_coroutine_variant + await not_coroutine_variant() + await self.not_coroutine_variant() + await not_coroutine_variant.call() + await call(&"not_coroutine_variant") + + await not_coroutine_void + await not_coroutine_void() + await self.not_coroutine_void() + await not_coroutine_void.call() + await call(&"not_coroutine_void") + + var callable: Callable = coroutine + await callable + await callable.call() + await callable.get_method() diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/redundant_await.out b/modules/gdscript/tests/scripts/analyzer/warnings/redundant_await.out new file mode 100644 index 00000000000..3d251c29062 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/redundant_await.out @@ -0,0 +1,37 @@ +GDTEST_OK +>> WARNING +>> Line: 26 +>> REDUNDANT_AWAIT +>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal. +>> WARNING +>> Line: 28 +>> REDUNDANT_AWAIT +>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal. +>> WARNING +>> Line: 32 +>> REDUNDANT_AWAIT +>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal. +>> WARNING +>> Line: 38 +>> REDUNDANT_AWAIT +>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal. +>> WARNING +>> Line: 44 +>> REDUNDANT_AWAIT +>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal. +>> WARNING +>> Line: 45 +>> REDUNDANT_AWAIT +>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal. +>> WARNING +>> Line: 46 +>> REDUNDANT_AWAIT +>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal. +>> WARNING +>> Line: 51 +>> REDUNDANT_AWAIT +>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal. +>> WARNING +>> Line: 53 +>> REDUNDANT_AWAIT +>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal. diff --git a/modules/gdscript/tests/scripts/runtime/features/await_without_coroutine.gd b/modules/gdscript/tests/scripts/runtime/features/await_without_coroutine.gd index 9da61ab1845..1c39073be98 100644 --- a/modules/gdscript/tests/scripts/runtime/features/await_without_coroutine.gd +++ b/modules/gdscript/tests/scripts/runtime/features/await_without_coroutine.gd @@ -4,5 +4,5 @@ func test(): print(await not_coroutine()) -func not_coroutine(): +func not_coroutine() -> String: return "awaited"