initial commit, 4.5 stable
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled

This commit is contained in:
2025-09-16 20:46:46 -04:00
commit 9d30169a8d
13378 changed files with 7050105 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
func test():
# These statements always evaluate to `true`, and therefore emit a warning.
assert(true)
assert(-1.234)
assert(2 + 3 == 5)

View File

@@ -0,0 +1,4 @@
GDTEST_OK
~~ WARNING at line 3: (ASSERT_ALWAYS_TRUE) Assert statement is redundant because the expression is always true.
~~ WARNING at line 4: (ASSERT_ALWAYS_TRUE) Assert statement is redundant because the expression is always true.
~~ WARNING at line 5: (ASSERT_ALWAYS_TRUE) Assert statement is redundant because the expression is always true.

View File

@@ -0,0 +1,12 @@
extends Node
func test():
var port = 0 # Only latin characters.
var pοrt = 1 # The "ο" is Greek omicron.
prints(port, pοrt)
# Do not call this since nodes aren't in the tree. It is just a parser check.
func nodes():
var _node1 = $port # Only latin characters.
var _node2 = $pοrt # The "ο" is Greek omicron.

View File

@@ -0,0 +1,4 @@
GDTEST_OK
~~ WARNING at line 5: (CONFUSABLE_IDENTIFIER) The identifier "pοrt" has misleading characters and might be confused with something else.
~~ WARNING at line 12: (CONFUSABLE_IDENTIFIER) The identifier "pοrt" has misleading characters and might be confused with something else.
0 1

View File

@@ -0,0 +1,8 @@
func test():
# `and` should be used instead.
if true && true:
pass
# `or` should be used instead.
if false || true:
pass

View File

@@ -0,0 +1 @@
GDTEST_OK

View File

@@ -0,0 +1,2 @@
GDTEST_OK
~~ WARNING at line 1: (EMPTY_FILE) Empty script file.

View File

@@ -0,0 +1 @@
# A comment.

View File

@@ -0,0 +1,2 @@
GDTEST_OK
~~ WARNING at line 1: (EMPTY_FILE) Empty script file.

View File

@@ -0,0 +1,2 @@
GDTEST_OK
~~ WARNING at line 1: (EMPTY_FILE) Empty script file.

View File

@@ -0,0 +1,4 @@
# A comment, followed by a bunch of newlines.

View File

@@ -0,0 +1,2 @@
GDTEST_OK
~~ WARNING at line 1: (EMPTY_FILE) Empty script file.

View File

@@ -0,0 +1,15 @@
enum MyEnum { ENUM_VALUE_1, ENUM_VALUE_2 }
# Assigning int value to enum-typed variable without explicit cast causes a warning.
# While it is valid it may be a mistake in the assignment.
var class_var: MyEnum = 0
func test():
print(class_var)
class_var = 1
print(class_var)
var local_var: MyEnum = 0
print(local_var)
local_var = 1
print(local_var)

View File

@@ -0,0 +1,9 @@
GDTEST_OK
~~ 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.
~~ 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.
~~ 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.
~~ 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.
0
1
0
1

View File

@@ -0,0 +1,8 @@
func test():
# The ternary operator below returns values of different types and the
# result is assigned to a typed variable. This will cause a run-time error
# if the branch with the incompatible type is picked. Here, it won't happen
# since the `false` condition never evaluates to `true`. Instead, a warning
# will be emitted.
var __: int = 25
__ = "hello" if false else -2

View File

@@ -0,0 +1,2 @@
GDTEST_OK
~~ WARNING at line 8: (INCOMPATIBLE_TERNARY) Values of the ternary operator are not mutually compatible.

View File

@@ -0,0 +1,10 @@
func test():
# This should emit a warning.
var __ = 5 / 2
# These should not emit warnings.
__ = float(5) / 2
__ = 5 / float(2)
__ = 5.0 / 2
__ = 5 / 2.0
__ = 5.0 / 2.0

View File

@@ -0,0 +1,2 @@
GDTEST_OK
~~ WARNING at line 3: (INTEGER_DIVISION) Integer division. Decimal part will be discarded.

View File

@@ -0,0 +1,9 @@
func test():
var i = 25
# The default branch (`_`) should be at the end of the `match` statement.
# Otherwise, a warning will be emitted
match i:
_:
print("default")
25:
print("is 25")

View File

@@ -0,0 +1,3 @@
GDTEST_OK
~~ WARNING at line 8: (UNREACHABLE_PATTERN) Unreachable pattern (pattern after wildcard or bind).
default

View File

@@ -0,0 +1,5 @@
func i_accept_ints_only(_i: int):
pass
func test():
i_accept_ints_only(12.345)

View File

@@ -0,0 +1,2 @@
GDTEST_OK
~~ WARNING at line 5: (NARROWING_CONVERSION) Narrowing conversion (float is converted to int and loses precision).

View File

@@ -0,0 +1,7 @@
func i_return_int() -> int:
return 4
func test():
i_return_int()
preload("../../utils.notest.gd") # `preload` is a function-like keyword.

View File

@@ -0,0 +1,3 @@
GDTEST_OK
~~ WARNING at line 6: (RETURN_VALUE_DISCARDED) The function "i_return_int()" returns a value that will be discarded if not used.
~~ WARNING at line 7: (RETURN_VALUE_DISCARDED) The function "preload()" returns a value that will be discarded if not used.

View File

@@ -0,0 +1,8 @@
# See also `parser-errors/redefine-class-constant.gd`.
const TEST = 25
func test():
# Warning here. This is not an error because a new constant is created,
# rather than attempting to set the value of an existing constant.
const TEST = 50

View File

@@ -0,0 +1,3 @@
GDTEST_OK
~~ WARNING at line 8: (UNUSED_LOCAL_CONSTANT) The local constant "TEST" is declared but never used in the block. If this is intended, prefix it with an underscore: "_TEST".
~~ WARNING at line 8: (SHADOWED_VARIABLE) The local constant "TEST" is shadowing an already-declared constant at line 2 in the current class.

View File

@@ -0,0 +1,2 @@
func test():
var abs = "This variable has the same name as the built-in function."

View File

@@ -0,0 +1,3 @@
GDTEST_OK
~~ WARNING at line 2: (UNUSED_VARIABLE) The local variable "abs" is declared but never used in the block. If this is intended, prefix it with an underscore: "_abs".
~~ WARNING at line 2: (SHADOWED_GLOBAL_IDENTIFIER) The variable "abs" has the same name as a built-in function.

View File

@@ -0,0 +1,8 @@
var foo = 123
func test():
# Notice the `var` keyword. Without this keyword, no warning would be emitted
# because no new variable would be created. Instead, the class variable's value
# would be overwritten.
var foo = 456

View File

@@ -0,0 +1,3 @@
GDTEST_OK
~~ WARNING at line 8: (UNUSED_VARIABLE) The local variable "foo" is declared but never used in the block. If this is intended, prefix it with an underscore: "_foo".
~~ WARNING at line 8: (SHADOWED_VARIABLE) The local variable "foo" is shadowing an already-declared variable at line 1 in the current class.

View File

@@ -0,0 +1,2 @@
func test():
var test = "This variable has the same name as the test() function."

View File

@@ -0,0 +1,3 @@
GDTEST_OK
~~ WARNING at line 2: (UNUSED_VARIABLE) The local variable "test" is declared but never used in the block. If this is intended, prefix it with an underscore: "_test".
~~ WARNING at line 2: (SHADOWED_VARIABLE) The local variable "test" is shadowing an already-declared function at line 1 in the current class.

View File

@@ -0,0 +1,21 @@
func test():
# The following statements should all be reported as standalone expressions:
1234
0.0 + 0.0
Color(1, 1, 1)
Vector3.ZERO
[true, false]
float(125)
# The following statements should not produce `STANDALONE_EXPRESSION`:
var _a = 1
_a = 2 # Assignment is a local (or global) side effect.
@warning_ignore("redundant_await")
await 3 # The `await` operand is usually a coroutine or a signal.
absi(4) # A call (in general) can have side effects.
@warning_ignore("return_value_discarded")
preload("../../utils.notest.gd") # A static initializer may have side effects.
"""
Python-like "comment".
"""
@warning_ignore("standalone_ternary")
1 if 2 else 3 # Produces `STANDALONE_TERNARY` instead.

View File

@@ -0,0 +1,5 @@
GDTEST_OK
~~ WARNING at line 3: (STANDALONE_EXPRESSION) Standalone expression (the line may have no effect).
~~ WARNING at line 4: (STANDALONE_EXPRESSION) Standalone expression (the line may have no effect).
~~ WARNING at line 6: (STANDALONE_EXPRESSION) Standalone expression (the line may have no effect).
~~ WARNING at line 7: (STANDALONE_EXPRESSION) Standalone expression (the line may have no effect).

View File

@@ -0,0 +1,3 @@
func test():
1 if true else 2
print(1) if true else print(2)

View File

@@ -0,0 +1,4 @@
GDTEST_OK
~~ WARNING at line 2: (STANDALONE_TERNARY) Standalone ternary operator (the return value is being discarded).
~~ WARNING at line 3: (STANDALONE_TERNARY) Standalone ternary operator (the return value is being discarded).
1

View File

@@ -0,0 +1,23 @@
class_name TestStaticCalledOnInstance
class Inner:
static func static_func():
pass
static func static_func():
pass
func test():
print(String.num_uint64(8589934592))
var some_string := String()
print(some_string.num_uint64(8589934592)) # Warning.
TestStaticCalledOnInstance.static_func()
static_func()
self.static_func()
var other := TestStaticCalledOnInstance.new()
other.static_func() # Warning.
Inner.static_func()
var inner := Inner.new()
inner.static_func() # Warning.

View File

@@ -0,0 +1,6 @@
GDTEST_OK
~~ WARNING at line 13: (STATIC_CALLED_ON_INSTANCE) The function "num_uint64()" is a static function but was called from an instance. Instead, it should be directly called from the type: "String.num_uint64()".
~~ WARNING at line 19: (STATIC_CALLED_ON_INSTANCE) The function "static_func()" is a static function but was called from an instance. Instead, it should be directly called from the type: "TestStaticCalledOnInstance.static_func()".
~~ WARNING at line 23: (STATIC_CALLED_ON_INSTANCE) The function "static_func()" is a static function but was called from an instance. Instead, it should be directly called from the type: "Inner.static_func()".
8589934592
8589934592

View File

@@ -0,0 +1,11 @@
func test():
var unassigned
print(unassigned)
unassigned = "something" # Assigned only after use.
var a
print(a) # Unassigned, warn.
if a: # Still unassigned, warn.
a = 1
print(a) # Assigned (dead code), don't warn.
print(a) # "Maybe" assigned, don't warn.

View File

@@ -0,0 +1,7 @@
GDTEST_OK
~~ WARNING at line 3: (UNASSIGNED_VARIABLE) The variable "unassigned" is used before being assigned a value.
~~ WARNING at line 7: (UNASSIGNED_VARIABLE) The variable "a" is used before being assigned a value.
~~ WARNING at line 8: (UNASSIGNED_VARIABLE) The variable "a" is used before being assigned a value.
<null>
<null>
<null>

View File

@@ -0,0 +1,4 @@
func test():
var __: int
# Variable has no set value at this point (even though it's implicitly `0` here).
__ += 15

View File

@@ -0,0 +1,2 @@
GDTEST_OK
~~ WARNING at line 4: (UNASSIGNED_VARIABLE_OP_ASSIGN) The variable "__" is modified with the compound-assignment operator "+=" but was not previously initialized.

View File

@@ -0,0 +1,7 @@
func test():
var i = 25
return
# This will never be run due to the `return` statement above.
print(i)

View File

@@ -0,0 +1,2 @@
GDTEST_OK
~~ WARNING at line 7: (UNREACHABLE_CODE) Unreachable code (statement after return) in function "test()".

View File

@@ -0,0 +1,16 @@
func test():
var foo := "bar"
match foo:
"baz":
return
_:
pass
match foo:
"baz":
return
match foo:
"bar":
pass
_:
return
print("reached")

View File

@@ -0,0 +1,2 @@
GDTEST_OK
reached

View File

@@ -0,0 +1,12 @@
# This should emit a warning since the unused argument is not prefixed with an underscore.
func function_with_unused_argument(p_arg1, p_arg2):
print(p_arg1)
# This shouldn't emit a warning since the unused argument is prefixed with an underscore.
func function_with_ignored_unused_argument(p_arg1, _p_arg2):
print(p_arg1)
func test():
pass

View File

@@ -0,0 +1,2 @@
GDTEST_OK
~~ WARNING at line 2: (UNUSED_PARAMETER) The parameter "p_arg2" is never used in the function "function_with_unused_argument()". If this is intended, prefix it with an underscore: "_p_arg2".

View File

@@ -0,0 +1,4 @@
func test():
const UNUSED = "not used"
const _UNUSED = "not used, but no warning since the constant name starts with an underscore"

View File

@@ -0,0 +1,2 @@
GDTEST_OK
~~ WARNING at line 2: (UNUSED_LOCAL_CONSTANT) The local constant "UNUSED" is declared but never used in the block. If this is intended, prefix it with an underscore: "_UNUSED".

View File

@@ -0,0 +1,4 @@
func test():
var unused = "not used"
var _unused = "not used, but no warning since the variable name starts with an underscore"

View File

@@ -0,0 +1,2 @@
GDTEST_OK
~~ WARNING at line 2: (UNUSED_VARIABLE) The local variable "unused" is declared but never used in the block. If this is intended, prefix it with an underscore: "_unused".