feat: godot-engine-source-4.3-stable

This commit is contained in:
Jan van der Weide 2025-01-17 16:36:38 +01:00
parent c59a7dcade
commit 7125d019b5
11149 changed files with 5070401 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,13 @@
GDTEST_OK
>> WARNING
>> Line: 3
>> ASSERT_ALWAYS_TRUE
>> Assert statement is redundant because the expression is always true.
>> WARNING
>> Line: 4
>> ASSERT_ALWAYS_TRUE
>> Assert statement is redundant because the expression is always true.
>> WARNING
>> 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,10 @@
GDTEST_OK
>> WARNING
>> Line: 5
>> CONFUSABLE_IDENTIFIER
>> The identifier "pοrt" has misleading characters and might be confused with something else.
>> WARNING
>> 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,4 @@
>> WARNING
>> Line: 1
>> EMPTY_FILE
>> Empty script file.

View file

@ -0,0 +1,4 @@
>> WARNING
>> Line: 1
>> EMPTY_FILE
>> Empty script file.

View file

@ -0,0 +1,4 @@
>> WARNING
>> 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,4 @@
>> WARNING
>> 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,21 @@
GDTEST_OK
>> WARNING
>> 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.
>> WARNING
>> 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.
>> WARNING
>> 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.
>> WARNING
>> 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.
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,5 @@
GDTEST_OK
>> WARNING
>> 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,5 @@
GDTEST_OK
>> WARNING
>> 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,6 @@
GDTEST_OK
>> WARNING
>> 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,5 @@
GDTEST_OK
>> WARNING
>> 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,9 @@
GDTEST_OK
>> WARNING
>> Line: 6
>> RETURN_VALUE_DISCARDED
>> The function "i_return_int()" returns a value that will be discarded if not used.
>> WARNING
>> 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,9 @@
GDTEST_OK
>> WARNING
>> 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
>> Line: 8
>> SHADOWED_VARIABLE
>> The local constant "TEST" is shadowing an already-declared constant at line 2.

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,9 @@
GDTEST_OK
>> WARNING
>> 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
>> 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,9 @@
GDTEST_OK
>> WARNING
>> 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
>> Line: 8
>> SHADOWED_VARIABLE
>> The local variable "foo" is shadowing an already-declared variable at line 1.

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,9 @@
GDTEST_OK
>> WARNING
>> 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
>> Line: 2
>> SHADOWED_VARIABLE
>> The local variable "test" is shadowing an already-declared function at line 1.

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,17 @@
GDTEST_OK
>> WARNING
>> Line: 3
>> STANDALONE_EXPRESSION
>> Standalone expression (the line may have no effect).
>> WARNING
>> Line: 4
>> STANDALONE_EXPRESSION
>> Standalone expression (the line may have no effect).
>> WARNING
>> Line: 6
>> STANDALONE_EXPRESSION
>> Standalone expression (the line may have no effect).
>> WARNING
>> 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,10 @@
GDTEST_OK
>> WARNING
>> Line: 2
>> STANDALONE_TERNARY
>> Standalone ternary operator: the return value is being discarded.
>> WARNING
>> 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,15 @@
GDTEST_OK
>> WARNING
>> 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
>> 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
>> 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,16 @@
GDTEST_OK
>> WARNING
>> Line: 3
>> UNASSIGNED_VARIABLE
>> The variable "unassigned" was used before being assigned a value.
>> WARNING
>> Line: 7
>> UNASSIGNED_VARIABLE
>> The variable "a" was used before being assigned a value.
>> WARNING
>> Line: 8
>> UNASSIGNED_VARIABLE
>> The variable "a" was 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,5 @@
GDTEST_OK
>> WARNING
>> Line: 4
>> UNASSIGNED_VARIABLE_OP_ASSIGN
>> Using assignment with operation but the variable "__" was not previously assigned a value.

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,5 @@
GDTEST_OK
>> WARNING
>> 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,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,5 @@
GDTEST_OK
>> WARNING
>> 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,5 @@
GDTEST_OK
>> WARNING
>> 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,5 @@
GDTEST_OK
>> WARNING
>> 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".