GDScript: Don't warn about RETURN_VALUE_DISCARDED by default

This happens too often with normal usage of the API.
The warning can still be useful to find actual bugs where discarding the return
value wasn't intentional, but this should stay enabled manually, at least until
we either improve the API to remove false positives, or improve the warning (e.g.
to only warn about unused return value on const functions).
This commit is contained in:
Rémi Verschelde 2022-11-22 14:36:51 +01:00
parent e3a51e53ef
commit 4abbb2d684
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 5 additions and 1 deletions

View File

@ -401,7 +401,7 @@
<member name="debug/gdscript/warnings/redundant_await" type="int" setter="" getter="" default="1"> <member name="debug/gdscript/warnings/redundant_await" type="int" setter="" getter="" default="1">
When set to [code]warn[/code] or [code]error[/code], produces a warning or an error respectively when a function that is not a coroutine is called with await. When set to [code]warn[/code] or [code]error[/code], produces a warning or an error respectively when a function that is not a coroutine is called with await.
</member> </member>
<member name="debug/gdscript/warnings/return_value_discarded" type="int" setter="" getter="" default="1"> <member name="debug/gdscript/warnings/return_value_discarded" type="int" setter="" getter="" default="0">
When set to [code]warn[/code] or [code]error[/code], produces a warning or an error respectively when calling a function without using its return value (by assigning it to a variable or using it as a function argument). Such return values are sometimes used to denote possible errors using the [enum Error] enum. When set to [code]warn[/code] or [code]error[/code], produces a warning or an error respectively when calling a function without using its return value (by assigning it to a variable or using it as a function argument). Such return values are sometimes used to denote possible errors using the [enum Error] enum.
</member> </member>
<member name="debug/gdscript/warnings/shadowed_global_identifier" type="int" setter="" getter="" default="1"> <member name="debug/gdscript/warnings/shadowed_global_identifier" type="int" setter="" getter="" default="1">

View File

@ -171,6 +171,10 @@ int GDScriptWarning::get_default_value(Code p_code) {
if (get_name_from_code(p_code).to_lower().begins_with("unsafe_")) { if (get_name_from_code(p_code).to_lower().begins_with("unsafe_")) {
return WarnLevel::IGNORE; return WarnLevel::IGNORE;
} }
// Too spammy by default on common cases (connect, Tween, etc.).
if (p_code == RETURN_VALUE_DISCARDED) {
return WarnLevel::IGNORE;
}
return WarnLevel::WARN; return WarnLevel::WARN;
} }