GDScript: Fix @warning_ignore annotation issues

This commit is contained in:
Danil Alexeev 2024-02-28 17:23:11 +03:00
parent 61282068f4
commit ef1909fca3
No known key found for this signature in database
GPG key ID: 124453E157DA8DC7
25 changed files with 603 additions and 209 deletions

View file

@ -52,13 +52,13 @@ String GDScriptWarning::get_message() const {
return vformat(R"(The local constant "%s" is declared but never used in the block. If this is intended, prefix it with an underscore: "_%s".)", symbols[0], symbols[0]);
case UNUSED_PRIVATE_CLASS_VARIABLE:
CHECK_SYMBOLS(1);
return vformat(R"(The class variable "%s" is declared but never used in the script.)", symbols[0]);
return vformat(R"(The class variable "%s" is declared but never used in the class.)", symbols[0]);
case UNUSED_PARAMETER:
CHECK_SYMBOLS(2);
return vformat(R"*(The parameter "%s" is never used in the function "%s()". If this is intended, prefix it with an underscore: "_%s".)*", symbols[1], symbols[0], symbols[1]);
case UNUSED_SIGNAL:
CHECK_SYMBOLS(1);
return vformat(R"(The signal "%s" is declared but never emitted.)", symbols[0]);
return vformat(R"(The signal "%s" is declared but never explicitly used in the class.)", symbols[0]);
case SHADOWED_VARIABLE:
CHECK_SYMBOLS(4);
return vformat(R"(The local %s "%s" is shadowing an already-declared %s at line %s.)", symbols[0], symbols[1], symbols[2], symbols[3]);
@ -76,18 +76,9 @@ String GDScriptWarning::get_message() const {
case STANDALONE_EXPRESSION:
return "Standalone expression (the line has no effect).";
case STANDALONE_TERNARY:
return "Standalone ternary conditional operator: the return value is being discarded.";
return "Standalone ternary operator: the return value is being discarded.";
case INCOMPATIBLE_TERNARY:
return "Values of the ternary conditional are not mutually compatible.";
case PROPERTY_USED_AS_FUNCTION:
CHECK_SYMBOLS(2);
return vformat(R"*(The method "%s()" was not found in base "%s" but there's a property with the same name. Did you mean to access it?)*", symbols[0], symbols[1]);
case CONSTANT_USED_AS_FUNCTION:
CHECK_SYMBOLS(2);
return vformat(R"*(The method "%s()" was not found in base "%s" but there's a constant with the same name. Did you mean to access it?)*", symbols[0], symbols[1]);
case FUNCTION_USED_AS_PROPERTY:
CHECK_SYMBOLS(2);
return vformat(R"(The property "%s" was not found in base "%s" but there's a method with the same name. Did you mean to call it?)", symbols[0], symbols[1]);
return "Values of the ternary operator are not mutually compatible.";
case UNTYPED_DECLARATION:
CHECK_SYMBOLS(2);
if (symbols[0] == "Function") {
@ -162,10 +153,17 @@ String GDScriptWarning::get_message() const {
return vformat(R"*(The default value is using "%s" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.)*", symbols[0]);
case ONREADY_WITH_EXPORT:
return R"("@onready" will set the default value after "@export" takes effect and will override it.)";
#ifndef DISABLE_DEPRECATED
// Never produced. These warnings migrated from 3.x by mistake.
case PROPERTY_USED_AS_FUNCTION: // There is already an error.
case CONSTANT_USED_AS_FUNCTION: // There is already an error.
case FUNCTION_USED_AS_PROPERTY: // This is valid, returns `Callable`.
break;
#endif
case WARNING_MAX:
break; // Can't happen, but silences warning
break; // Can't happen, but silences warning.
}
ERR_FAIL_V_MSG(String(), "Invalid GDScript warning code: " + get_name_from_code(code) + ".");
ERR_FAIL_V_MSG(String(), vformat(R"(Invalid GDScript warning "%s".)", get_name_from_code(code)));
#undef CHECK_SYMBOLS
}
@ -206,9 +204,6 @@ String GDScriptWarning::get_name_from_code(Code p_code) {
"STANDALONE_EXPRESSION",
"STANDALONE_TERNARY",
"INCOMPATIBLE_TERNARY",
"PROPERTY_USED_AS_FUNCTION",
"CONSTANT_USED_AS_FUNCTION",
"FUNCTION_USED_AS_PROPERTY",
"UNTYPED_DECLARATION",
"INFERRED_DECLARATION",
"UNSAFE_PROPERTY_ACCESS",
@ -236,6 +231,11 @@ String GDScriptWarning::get_name_from_code(Code p_code) {
"NATIVE_METHOD_OVERRIDE",
"GET_NODE_DEFAULT_WITHOUT_ONREADY",
"ONREADY_WITH_EXPORT",
#ifndef DISABLE_DEPRECATED
"PROPERTY_USED_AS_FUNCTION",
"CONSTANT_USED_AS_FUNCTION",
"FUNCTION_USED_AS_PROPERTY",
#endif
};
static_assert((sizeof(names) / sizeof(*names)) == WARNING_MAX, "Amount of warning types don't match the amount of warning names.");