From 5d0b183822052e894c98d8d0ea997e0afddc93ed Mon Sep 17 00:00:00 2001 From: Dmitrii Maganov Date: Fri, 17 Mar 2023 05:36:50 +0200 Subject: [PATCH] GDScript: Allow usage of literal false in assert without a warning --- modules/gdscript/gdscript_analyzer.cpp | 2 +- .../tests/scripts/analyzer/features/assert_literal_false.gd | 6 ++++++ .../scripts/analyzer/features/assert_literal_false.out | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 modules/gdscript/tests/scripts/analyzer/features/assert_literal_false.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/features/assert_literal_false.out diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 38d5ae6b77c..607d9f034fc 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -2007,7 +2007,7 @@ void GDScriptAnalyzer::resolve_assert(GDScriptParser::AssertNode *p_assert) { if (p_assert->condition->is_constant) { if (p_assert->condition->reduced_value.booleanize()) { parser->push_warning(p_assert->condition, GDScriptWarning::ASSERT_ALWAYS_TRUE); - } else { + } else if (!(p_assert->condition->type == GDScriptParser::Node::LITERAL && static_cast(p_assert->condition)->value.get_type() == Variant::BOOL)) { parser->push_warning(p_assert->condition, GDScriptWarning::ASSERT_ALWAYS_FALSE); } } diff --git a/modules/gdscript/tests/scripts/analyzer/features/assert_literal_false.gd b/modules/gdscript/tests/scripts/analyzer/features/assert_literal_false.gd new file mode 100644 index 00000000000..d6c3cfc50e4 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/assert_literal_false.gd @@ -0,0 +1,6 @@ +func test(): + var never: Variant = false + if never: + assert(false) + assert(false, 'message') + print('ok') diff --git a/modules/gdscript/tests/scripts/analyzer/features/assert_literal_false.out b/modules/gdscript/tests/scripts/analyzer/features/assert_literal_false.out new file mode 100644 index 00000000000..1b47ed10dc0 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/assert_literal_false.out @@ -0,0 +1,2 @@ +GDTEST_OK +ok