Skip to content

Commit d8db03e

Browse files
committed
Fix a few GDScript warning messages for grammar and consistency
Regenerate test results Improve warning message for `INT_AS_ENUM_WITHOUT_CAST` Improve `REDUNDANT_AWAIT` message and regenerate tests Allow warning message for UNASSIGNED_VARIABLE_OP_ASSIGN to display specific operator Remove "being" from some messages to make them consistent and clearer Update expected test results Use Variant::get_operator_name for determining string representation of operator instead of big switch-case Update tests Update modules/gdscript/gdscript_warning.cpp Co-authored-by: Danil Alexeev <[email protected]> Update tests... again
1 parent 6a6a116 commit d8db03e

File tree

11 files changed

+57
-57
lines changed

11 files changed

+57
-57
lines changed

modules/gdscript/gdscript_analyzer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3011,7 +3011,7 @@ void GDScriptAnalyzer::reduce_assignment(GDScriptParser::AssignmentNode *p_assig
30113011
GDScriptParser::IdentifierNode *id = static_cast<GDScriptParser::IdentifierNode *>(p_assignment->assignee);
30123012
// Use == 1 here because this assignment was already counted in the beginning of the function.
30133013
if (id->source == GDScriptParser::IdentifierNode::LOCAL_VARIABLE && id->variable_source && id->variable_source->assignments == 1) {
3014-
parser->push_warning(p_assignment, GDScriptWarning::UNASSIGNED_VARIABLE_OP_ASSIGN, id->name);
3014+
parser->push_warning(p_assignment, GDScriptWarning::UNASSIGNED_VARIABLE_OP_ASSIGN, id->name, Variant::get_operator_name(p_assignment->variant_op));
30153015
}
30163016
}
30173017
#endif

modules/gdscript/gdscript_warning.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ String GDScriptWarning::get_message() const {
4040
switch (code) {
4141
case UNASSIGNED_VARIABLE:
4242
CHECK_SYMBOLS(1);
43-
return vformat(R"(The variable "%s" was used before being assigned a value.)", symbols[0]);
43+
return vformat(R"(The variable "%s" is used before being assigned a value.)", symbols[0]);
4444
case UNASSIGNED_VARIABLE_OP_ASSIGN:
45-
CHECK_SYMBOLS(1);
46-
return vformat(R"(Using assignment with operation but the variable "%s" was not previously assigned a value.)", symbols[0]);
45+
CHECK_SYMBOLS(2);
46+
return vformat(R"(The variable "%s" is modified with the compound-assignment operator "%s=" but was not previously initialized.)", symbols[0], symbols[1]);
4747
case UNUSED_VARIABLE:
4848
CHECK_SYMBOLS(1);
4949
return vformat(R"(The local variable "%s" is declared but never used in the block. If this is intended, prefix it with an underscore: "_%s".)", symbols[0], symbols[0]);
@@ -79,7 +79,7 @@ String GDScriptWarning::get_message() const {
7979
case STANDALONE_EXPRESSION:
8080
return "Standalone expression (the line may have no effect).";
8181
case STANDALONE_TERNARY:
82-
return "Standalone ternary operator: the return value is being discarded.";
82+
return "Standalone ternary operator (the return value is being discarded).";
8383
case INCOMPATIBLE_TERNARY:
8484
return "Values of the ternary operator are not mutually compatible.";
8585
case UNTYPED_DECLARATION:
@@ -117,17 +117,17 @@ String GDScriptWarning::get_message() const {
117117
case REDUNDANT_STATIC_UNLOAD:
118118
return R"(The "@static_unload" annotation is redundant because the file does not have a class with static variables.)";
119119
case REDUNDANT_AWAIT:
120-
return R"("await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.)";
120+
return R"("await" keyword is unnecessary because the expression isn't a coroutine nor a signal.)";
121121
case ASSERT_ALWAYS_TRUE:
122122
return "Assert statement is redundant because the expression is always true.";
123123
case ASSERT_ALWAYS_FALSE:
124124
return "Assert statement will raise an error because the expression is always false.";
125125
case INTEGER_DIVISION:
126-
return "Integer division, decimal part will be discarded.";
126+
return "Integer division. Decimal part will be discarded.";
127127
case NARROWING_CONVERSION:
128128
return "Narrowing conversion (float is converted to int and loses precision).";
129129
case INT_AS_ENUM_WITHOUT_CAST:
130-
return "Integer used when an enum value is expected. If this is intended cast the integer to the enum type.";
130+
return "Integer used when an enum value is expected. If this is intended, cast the integer to the enum type using the \"as\" keyword.";
131131
case INT_AS_ENUM_WITHOUT_MATCH:
132132
CHECK_SYMBOLS(3);
133133
return vformat(R"(Cannot %s %s as Enum "%s": no enum member has matching value.)", symbols[0], symbols[1], symbols[2]);
@@ -138,7 +138,7 @@ String GDScriptWarning::get_message() const {
138138
return "Empty script file.";
139139
case DEPRECATED_KEYWORD:
140140
CHECK_SYMBOLS(2);
141-
return vformat(R"(The "%s" keyword is deprecated and will be removed in a future release, please replace its uses by "%s".)", symbols[0], symbols[1]);
141+
return vformat(R"(The "%s" keyword is deprecated and will be removed in a future release. Please replace it with "%s".)", symbols[0], symbols[1]);
142142
case CONFUSABLE_IDENTIFIER:
143143
CHECK_SYMBOLS(1);
144144
return vformat(R"(The identifier "%s" has misleading characters and might be confused with something else.)", symbols[0]);
@@ -159,7 +159,7 @@ String GDScriptWarning::get_message() const {
159159
return vformat(R"*(The method "%s()" overrides a method from native class "%s". This won't be called by the engine and may not work as expected.)*", symbols[0], symbols[1]);
160160
case GET_NODE_DEFAULT_WITHOUT_ONREADY:
161161
CHECK_SYMBOLS(1);
162-
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]);
162+
return vformat(R"*(The default value uses "%s" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.)*", symbols[0]);
163163
case ONREADY_WITH_EXPORT:
164164
return R"("@onready" will set the default value after "@export" takes effect and will override it.)";
165165
#ifndef DISABLE_DEPRECATED
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
GDTEST_OK
2-
~~ WARNING at line 5: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value is using "$" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
3-
~~ WARNING at line 6: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value is using "get_node()" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
4-
~~ WARNING at line 7: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value is using "get_node()" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
5-
~~ WARNING at line 8: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value is using "get_node()" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
6-
~~ WARNING at line 9: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value is using "$" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
7-
~~ WARNING at line 11: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value is using "%" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
8-
~~ WARNING at line 12: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value is using "$" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
9-
~~ WARNING at line 13: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value is using "get_node()" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
10-
~~ WARNING at line 14: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value is using "%" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
2+
~~ WARNING at line 5: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value uses "$" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
3+
~~ WARNING at line 6: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value uses "get_node()" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
4+
~~ WARNING at line 7: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value uses "get_node()" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
5+
~~ WARNING at line 8: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value uses "get_node()" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
6+
~~ WARNING at line 9: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value uses "$" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
7+
~~ WARNING at line 11: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value uses "%" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
8+
~~ WARNING at line 12: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value uses "$" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
9+
~~ WARNING at line 13: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value uses "get_node()" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
10+
~~ WARNING at line 14: (GET_NODE_DEFAULT_WITHOUT_ONREADY) The default value uses "%" which won't return nodes in the scene tree before "_ready()" is called. Use the "@onready" annotation to solve this.
1111
warn
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
GDTEST_OK
2-
~~ WARNING at line 26: (REDUNDANT_AWAIT) "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.
3-
~~ WARNING at line 28: (REDUNDANT_AWAIT) "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.
4-
~~ WARNING at line 32: (REDUNDANT_AWAIT) "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.
5-
~~ WARNING at line 38: (REDUNDANT_AWAIT) "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.
6-
~~ WARNING at line 44: (REDUNDANT_AWAIT) "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.
7-
~~ WARNING at line 45: (REDUNDANT_AWAIT) "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.
8-
~~ WARNING at line 46: (REDUNDANT_AWAIT) "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.
9-
~~ WARNING at line 51: (REDUNDANT_AWAIT) "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.
10-
~~ WARNING at line 53: (REDUNDANT_AWAIT) "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.
2+
~~ WARNING at line 26: (REDUNDANT_AWAIT) "await" keyword is unnecessary because the expression isn't a coroutine nor a signal.
3+
~~ WARNING at line 28: (REDUNDANT_AWAIT) "await" keyword is unnecessary because the expression isn't a coroutine nor a signal.
4+
~~ WARNING at line 32: (REDUNDANT_AWAIT) "await" keyword is unnecessary because the expression isn't a coroutine nor a signal.
5+
~~ WARNING at line 38: (REDUNDANT_AWAIT) "await" keyword is unnecessary because the expression isn't a coroutine nor a signal.
6+
~~ WARNING at line 44: (REDUNDANT_AWAIT) "await" keyword is unnecessary because the expression isn't a coroutine nor a signal.
7+
~~ WARNING at line 45: (REDUNDANT_AWAIT) "await" keyword is unnecessary because the expression isn't a coroutine nor a signal.
8+
~~ WARNING at line 46: (REDUNDANT_AWAIT) "await" keyword is unnecessary because the expression isn't a coroutine nor a signal.
9+
~~ WARNING at line 51: (REDUNDANT_AWAIT) "await" keyword is unnecessary because the expression isn't a coroutine nor a signal.
10+
~~ WARNING at line 53: (REDUNDANT_AWAIT) "await" keyword is unnecessary because the expression isn't a coroutine nor a signal.

modules/gdscript/tests/scripts/parser/features/nested_arithmetic.out

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
GDTEST_OK
2-
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
3-
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
4-
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
5-
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
6-
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
7-
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
8-
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
9-
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
10-
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
11-
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
12-
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
13-
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
14-
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
15-
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
16-
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
17-
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
18-
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
2+
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
3+
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
4+
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
5+
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
6+
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
7+
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
8+
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
9+
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
10+
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
11+
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
12+
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
13+
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
14+
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
15+
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
16+
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
17+
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
18+
~~ WARNING at line 19: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
1919
2.718
2020

2121
2.718

modules/gdscript/tests/scripts/parser/warnings/enum_assign_int_without_casting.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
GDTEST_OK
2-
~~ WARNING at line 5: (INT_AS_ENUM_WITHOUT_CAST) Integer used when an enum value is expected. If this is intended cast the integer to the enum type.
3-
~~ WARNING at line 9: (INT_AS_ENUM_WITHOUT_CAST) Integer used when an enum value is expected. If this is intended cast the integer to the enum type.
4-
~~ WARNING at line 12: (INT_AS_ENUM_WITHOUT_CAST) Integer used when an enum value is expected. If this is intended cast the integer to the enum type.
5-
~~ WARNING at line 14: (INT_AS_ENUM_WITHOUT_CAST) Integer used when an enum value is expected. If this is intended cast the integer to the enum type.
2+
~~ WARNING at line 5: (INT_AS_ENUM_WITHOUT_CAST) Integer used when an enum value is expected. If this is intended, cast the integer to the enum type using the "as" keyword.
3+
~~ WARNING at line 9: (INT_AS_ENUM_WITHOUT_CAST) Integer used when an enum value is expected. If this is intended, cast the integer to the enum type using the "as" keyword.
4+
~~ WARNING at line 12: (INT_AS_ENUM_WITHOUT_CAST) Integer used when an enum value is expected. If this is intended, cast the integer to the enum type using the "as" keyword.
5+
~~ WARNING at line 14: (INT_AS_ENUM_WITHOUT_CAST) Integer used when an enum value is expected. If this is intended, cast the integer to the enum type using the "as" keyword.
66
0
77
1
88
0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
GDTEST_OK
2-
~~ WARNING at line 3: (INTEGER_DIVISION) Integer division, decimal part will be discarded.
2+
~~ WARNING at line 3: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
GDTEST_OK
2-
~~ WARNING at line 2: (STANDALONE_TERNARY) Standalone ternary operator: the return value is being discarded.
3-
~~ WARNING at line 3: (STANDALONE_TERNARY) Standalone ternary operator: the return value is being discarded.
2+
~~ WARNING at line 2: (STANDALONE_TERNARY) Standalone ternary operator (the return value is being discarded).
3+
~~ WARNING at line 3: (STANDALONE_TERNARY) Standalone ternary operator (the return value is being discarded).
44
1
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GDTEST_OK
2-
~~ WARNING at line 3: (UNASSIGNED_VARIABLE) The variable "unassigned" was used before being assigned a value.
3-
~~ WARNING at line 7: (UNASSIGNED_VARIABLE) The variable "a" was used before being assigned a value.
4-
~~ WARNING at line 8: (UNASSIGNED_VARIABLE) The variable "a" was used before being assigned a value.
2+
~~ WARNING at line 3: (UNASSIGNED_VARIABLE) The variable "unassigned" is used before being assigned a value.
3+
~~ WARNING at line 7: (UNASSIGNED_VARIABLE) The variable "a" is used before being assigned a value.
4+
~~ WARNING at line 8: (UNASSIGNED_VARIABLE) The variable "a" is used before being assigned a value.
55
<null>
66
<null>
77
<null>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
GDTEST_OK
2-
~~ WARNING at line 4: (UNASSIGNED_VARIABLE_OP_ASSIGN) Using assignment with operation but the variable "__" was not previously assigned a value.
2+
~~ WARNING at line 4: (UNASSIGNED_VARIABLE_OP_ASSIGN) The variable "__" is modified with the compound-assignment operator "+=" but was not previously initialized.

0 commit comments

Comments
 (0)