From d00eb583814cb4c051c379fb55eb259e8ecb5208 Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Tue, 18 Apr 2023 14:08:48 +0300 Subject: [PATCH] GDScript: Fix warning ignoring for member variables (cherry picked from commit c2fbb40e9ab045a5eadbd013f3a23e54fce45191) --- modules/gdscript/gdscript_analyzer.cpp | 7 ++++--- .../analyzer/warnings/unused_private_class_variable.gd | 10 ++++++++++ .../warnings/unused_private_class_variable.out | 9 +++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 modules/gdscript/tests/scripts/analyzer/warnings/unused_private_class_variable.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/warnings/unused_private_class_variable.out diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 470003928e9..0bef94b1789 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -1308,10 +1308,11 @@ void GDScriptAnalyzer::resolve_class_body(GDScriptParser::ClassNode *p_class, co push_error(vformat(R"(Getter with type "%s" cannot be used along with setter of type "%s".)", getter_function->datatype.to_string(), setter_function->parameters[0]->datatype.to_string()), member.variable); } } -#ifdef DEBUG_ENABLED - parser->ignored_warnings = previously_ignored_warnings; -#endif // DEBUG_ENABLED } + +#ifdef DEBUG_ENABLED + parser->ignored_warnings = previously_ignored_warnings; +#endif // DEBUG_ENABLED } } diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/unused_private_class_variable.gd b/modules/gdscript/tests/scripts/analyzer/warnings/unused_private_class_variable.gd new file mode 100644 index 00000000000..5ca8ceffddc --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/unused_private_class_variable.gd @@ -0,0 +1,10 @@ +# GH-72135 + +var _a +@warning_ignore("unused_private_class_variable") +var _b +@warning_ignore("unused_private_class_variable") var _c +var _d + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/unused_private_class_variable.out b/modules/gdscript/tests/scripts/analyzer/warnings/unused_private_class_variable.out new file mode 100644 index 00000000000..8713db4d4ee --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/unused_private_class_variable.out @@ -0,0 +1,9 @@ +GDTEST_OK +>> WARNING +>> Line: 3 +>> UNUSED_PRIVATE_CLASS_VARIABLE +>> The class variable '_a' is declared but never used in the script. +>> WARNING +>> Line: 7 +>> UNUSED_PRIVATE_CLASS_VARIABLE +>> The class variable '_d' is declared but never used in the script.