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 @@
enum MyEnum { ENUM_VALUE_1, ENUM_VALUE_2 }
enum MyOtherEnum { OTHER_ENUM_VALUE_1, OTHER_ENUM_VALUE_2, OTHER_ENUM_VALUE_3 }
func test():
print(MyOtherEnum.OTHER_ENUM_VALUE_3 as MyEnum)

View file

@ -0,0 +1,6 @@
GDTEST_OK
>> WARNING
>> Line: 5
>> INT_AS_ENUM_WITHOUT_MATCH
>> Cannot cast 2 as Enum "cast_enum_bad_enum.gd.MyEnum": no enum member has matching value.
2

View file

@ -0,0 +1,4 @@
enum MyEnum { ENUM_VALUE_1, ENUM_VALUE_2 }
func test():
print(2 as MyEnum)

View file

@ -0,0 +1,6 @@
GDTEST_OK
>> WARNING
>> Line: 4
>> INT_AS_ENUM_WITHOUT_MATCH
>> Cannot cast 2 as Enum "cast_enum_bad_int.gd.MyEnum": no enum member has matching value.
2

View file

@ -0,0 +1,23 @@
var member := 1
func test():
var number := 1
var string := "1"
var vector := Vector2i(1, 0)
var array_assign := [1]
var array_index := [1]
var dictionary := { x = 0 }
var lambda := func ():
member = 2 # Member variable, not captured.
number = 2 # Local variable, captured.
string += "2" # Test compound assignment operator.
vector.x = 2 # Test subscript assignment.
array_assign = [2] # Pass-by-reference type, reassignment.
array_index[0] = 2 # Pass-by-reference type, index access.
dictionary.x = 2 # Pass-by-reference type, attribute access.
prints("lambda", member, number, string, vector, array_assign, array_index, dictionary)
lambda.call()
prints("outer", member, number, string, vector, array_assign, array_index, dictionary)

View file

@ -0,0 +1,19 @@
GDTEST_OK
>> WARNING
>> Line: 13
>> CONFUSABLE_CAPTURE_REASSIGNMENT
>> Reassigning lambda capture does not modify the outer local variable "number".
>> WARNING
>> Line: 14
>> CONFUSABLE_CAPTURE_REASSIGNMENT
>> Reassigning lambda capture does not modify the outer local variable "string".
>> WARNING
>> Line: 15
>> CONFUSABLE_CAPTURE_REASSIGNMENT
>> Reassigning lambda capture does not modify the outer local variable "vector".
>> WARNING
>> Line: 16
>> CONFUSABLE_CAPTURE_REASSIGNMENT
>> Reassigning lambda capture does not modify the outer local variable "array_assign".
lambda 2 2 12 (2, 0) [2] [2] { "x": 2 }
outer 2 1 1 (1, 0) [1] [2] { "x": 2 }

View file

@ -0,0 +1,6 @@
func test():
if true:
var a = 1
print(a)
var a = 2
print(a)

View file

@ -0,0 +1,7 @@
GDTEST_OK
>> WARNING
>> Line: 3
>> CONFUSABLE_LOCAL_DECLARATION
>> The variable "a" is declared below in the parent block.
1
2

View file

@ -0,0 +1,6 @@
var a = 1
func test():
print(a)
var a = 2
print(a)

View file

@ -0,0 +1,11 @@
GDTEST_OK
>> WARNING
>> Line: 4
>> CONFUSABLE_LOCAL_USAGE
>> The identifier "a" will be shadowed below in the block.
>> WARNING
>> Line: 5
>> SHADOWED_VARIABLE
>> The local variable "a" is shadowing an already-declared variable at line 1.
1
2

View file

@ -0,0 +1,6 @@
var a = 1
func test():
print(a)
var a = a + 1
print(a)

View file

@ -0,0 +1,15 @@
GDTEST_OK
>> WARNING
>> Line: 4
>> CONFUSABLE_LOCAL_USAGE
>> The identifier "a" will be shadowed below in the block.
>> WARNING
>> Line: 5
>> CONFUSABLE_LOCAL_USAGE
>> The identifier "a" will be shadowed below in the block.
>> WARNING
>> Line: 5
>> SHADOWED_VARIABLE
>> The local variable "a" is shadowing an already-declared variable at line 1.
1
2

View file

@ -0,0 +1,7 @@
var a = 1
func test():
for _i in 3:
print(a)
var a = 2
print(a)

View file

@ -0,0 +1,15 @@
GDTEST_OK
>> WARNING
>> Line: 5
>> CONFUSABLE_LOCAL_USAGE
>> The identifier "a" will be shadowed below in the block.
>> WARNING
>> Line: 6
>> SHADOWED_VARIABLE
>> The local variable "a" is shadowing an already-declared variable at line 1.
1
2
1
2
1
2

View file

@ -0,0 +1,23 @@
enum HasZero { A = 0, B = 1 }
enum HasNoZero { A = 1, B = 2 }
var has_zero: HasZero # No warning, because the default `0` is valid.
var has_no_zero: HasNoZero # Warning, because there is no `0` in the enum.
func test():
print(has_zero)
print(has_no_zero)
# GH-94634. A parameter is either mandatory or has a default value.
func test_no_exec(param: HasNoZero) -> void:
print(param)
# Loop iterator always has a value.
for i: HasNoZero in HasNoZero.values():
print(i)
match param:
# Pattern bind always has a value.
var x:
print(x)

View file

@ -0,0 +1,7 @@
GDTEST_OK
>> WARNING
>> Line: 4
>> ENUM_VARIABLE_WITHOUT_DEFAULT
>> The variable "has_no_zero" has an enum type and does not set an explicit default value. The default will be set to "0".
0
0

View file

@ -0,0 +1,18 @@
extends Node
var add_node = do_add_node() # Hack to have one node on init and not fail at runtime.
var shorthand = $Node
var with_self = self.get_node(^"Node")
var without_self = get_node(^"Node")
var with_cast = get_node(^"Node") as Node
var shorthand_with_cast = $Node as Node
func test():
print("warn")
func do_add_node():
var node = Node.new()
node.name = "Node"
@warning_ignore("unsafe_call_argument")
add_child(node)

View file

@ -0,0 +1,22 @@
GDTEST_OK
>> WARNING
>> 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.
>> WARNING
>> 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.
>> WARNING
>> 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.
>> WARNING
>> 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.
>> WARNING
>> 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.
warn

View file

@ -0,0 +1,6 @@
func test():
var inferred_with_variant := return_variant()
print(inferred_with_variant)
func return_variant() -> Variant:
return "warn"

View file

@ -0,0 +1,6 @@
GDTEST_OK
>> WARNING
>> Line: 2
>> INFERENCE_ON_VARIANT
>> The variable type is being inferred from a Variant value, so it will be typed as Variant.
warn

View file

@ -0,0 +1,6 @@
var shadow: int
func test():
var lambda := func(shadow: String) -> void:
print(shadow)
lambda.call('shadow')

View file

@ -0,0 +1,6 @@
GDTEST_OK
>> WARNING
>> Line: 4
>> SHADOWED_VARIABLE
>> The local function parameter "shadow" is shadowing an already-declared variable at line 1.
shadow

View file

@ -0,0 +1,4 @@
func test():
var lambda := func(unused: Variant) -> void:
pass
lambda.call("something")

View file

@ -0,0 +1,5 @@
GDTEST_OK
>> WARNING
>> Line: 2
>> UNUSED_PARAMETER
>> The parameter "unused" is never used in the function "<anonymous lambda>()". If this is intended, prefix it with an underscore: "_unused".

View file

@ -0,0 +1,6 @@
extends Node
@onready @export var conflict = ""
func test():
print("warn")

View file

@ -0,0 +1,6 @@
GDTEST_OK
>> WARNING
>> Line: 3
>> ONREADY_WITH_EXPORT
>> "@onready" will set the default value after "@export" takes effect and will override it.
warn

View file

@ -0,0 +1,5 @@
func test():
print("warn")
func get(_property: StringName) -> Variant:
return null

View file

@ -0,0 +1,6 @@
GDTEST_OK
>> WARNING
>> Line: 4
>> NATIVE_METHOD_OVERRIDE
>> The method "get()" overrides a method from native class "Object". This won't be called by the engine and may not work as expected.
warn

View file

@ -0,0 +1,53 @@
signal my_signal()
# CI cannot test async things.
func test_signals():
await my_signal
var t: Signal = my_signal
await t
func coroutine() -> void:
@warning_ignore("redundant_await")
await 0
func not_coroutine_variant():
pass
func not_coroutine_void() -> void:
pass
func test():
const CONST_NULL = null
var var_null = null
var var_int: int = 1
var var_variant: Variant = 1
var var_array: Array = [1]
await CONST_NULL
await var_null
await var_int
await var_variant
await var_array[0]
await coroutine
await coroutine()
await coroutine.call()
await self.coroutine()
await call(&"coroutine")
await not_coroutine_variant
await not_coroutine_variant()
await self.not_coroutine_variant()
await not_coroutine_variant.call()
await call(&"not_coroutine_variant")
await not_coroutine_void
await not_coroutine_void()
await self.not_coroutine_void()
await not_coroutine_void.call()
await call(&"not_coroutine_void")
var callable: Callable = coroutine
await callable
await callable.call()
await callable.get_method()

View file

@ -0,0 +1,37 @@
GDTEST_OK
>> WARNING
>> Line: 26
>> REDUNDANT_AWAIT
>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.
>> WARNING
>> Line: 28
>> REDUNDANT_AWAIT
>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.
>> WARNING
>> Line: 32
>> REDUNDANT_AWAIT
>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.
>> WARNING
>> Line: 38
>> REDUNDANT_AWAIT
>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.
>> WARNING
>> Line: 44
>> REDUNDANT_AWAIT
>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.
>> WARNING
>> Line: 45
>> REDUNDANT_AWAIT
>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.
>> WARNING
>> Line: 46
>> REDUNDANT_AWAIT
>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.
>> WARNING
>> Line: 51
>> REDUNDANT_AWAIT
>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.
>> WARNING
>> Line: 53
>> REDUNDANT_AWAIT
>> "await" keyword not needed in this case, because the expression isn't a coroutine nor a signal.

View file

@ -0,0 +1,19 @@
class_name ShadowedClass
var member: int = 0
var print_debug := 'print_debug'
@warning_ignore("shadowed_global_identifier")
var print := 'print'
@warning_ignore("unused_variable")
func test():
var Array := 'Array'
var Node := 'Node'
var is_same := 'is_same'
var sqrt := 'sqrt'
var member := 'member'
var reference := 'reference'
var ShadowedClass := 'ShadowedClass'
print('warn')

View file

@ -0,0 +1,34 @@
GDTEST_OK
>> WARNING
>> Line: 5
>> SHADOWED_GLOBAL_IDENTIFIER
>> The variable "print_debug" has the same name as a built-in function.
>> WARNING
>> Line: 11
>> SHADOWED_GLOBAL_IDENTIFIER
>> The variable "Array" has the same name as a built-in type.
>> WARNING
>> Line: 12
>> SHADOWED_GLOBAL_IDENTIFIER
>> The variable "Node" has the same name as a native class.
>> WARNING
>> Line: 13
>> SHADOWED_GLOBAL_IDENTIFIER
>> The variable "is_same" has the same name as a built-in function.
>> WARNING
>> Line: 14
>> SHADOWED_GLOBAL_IDENTIFIER
>> The variable "sqrt" has the same name as a built-in function.
>> WARNING
>> Line: 15
>> SHADOWED_VARIABLE
>> The local variable "member" is shadowing an already-declared variable at line 3.
>> WARNING
>> Line: 16
>> SHADOWED_VARIABLE_BASE_CLASS
>> The local variable "reference" is shadowing an already-declared method at the base class "RefCounted".
>> WARNING
>> Line: 17
>> SHADOWED_GLOBAL_IDENTIFIER
>> The variable "ShadowedClass" has the same name as a global class defined in "shadowning.gd".
warn

View file

@ -0,0 +1,54 @@
func variant_func(x: Variant) -> void:
print(x)
func int_func(x: int) -> void:
print(x)
func float_func(x: float) -> void:
print(x)
func node_func(x: Node) -> void:
print(x)
# We don't want to execute it because of errors, just analyze.
func no_exec_test():
var variant: Variant = null
var untyped_int = 42
var untyped_string = "abc"
var variant_int: Variant = 42
var variant_string: Variant = "abc"
var typed_int: int = 42
variant_func(untyped_int) # No warning.
variant_func(untyped_string) # No warning.
variant_func(variant_int) # No warning.
variant_func(variant_string) # No warning.
variant_func(typed_int) # No warning.
int_func(untyped_int)
int_func(untyped_string)
int_func(variant_int)
int_func(variant_string)
int_func(typed_int) # No warning.
float_func(untyped_int)
float_func(untyped_string)
float_func(variant_int)
float_func(variant_string)
float_func(typed_int) # No warning.
node_func(variant)
node_func(Object.new())
node_func(Node.new()) # No warning.
node_func(Node2D.new()) # No warning.
# GH-82529
print(Callable(self, "test")) # No warning.
print(Callable(variant, "test"))
print(Dictionary(variant))
print(Vector2(variant))
print(int(variant))
func test():
pass

View file

@ -0,0 +1,57 @@
GDTEST_OK
>> WARNING
>> Line: 28
>> UNSAFE_CALL_ARGUMENT
>> The argument 1 of the function "int_func()" requires the subtype "int" but the supertype "Variant" was provided.
>> WARNING
>> Line: 29
>> UNSAFE_CALL_ARGUMENT
>> The argument 1 of the function "int_func()" requires the subtype "int" but the supertype "Variant" was provided.
>> WARNING
>> Line: 30
>> UNSAFE_CALL_ARGUMENT
>> The argument 1 of the function "int_func()" requires the subtype "int" but the supertype "Variant" was provided.
>> WARNING
>> Line: 31
>> UNSAFE_CALL_ARGUMENT
>> The argument 1 of the function "int_func()" requires the subtype "int" but the supertype "Variant" was provided.
>> WARNING
>> Line: 34
>> UNSAFE_CALL_ARGUMENT
>> The argument 1 of the function "float_func()" requires the subtype "float" but the supertype "Variant" was provided.
>> WARNING
>> Line: 35
>> UNSAFE_CALL_ARGUMENT
>> The argument 1 of the function "float_func()" requires the subtype "float" but the supertype "Variant" was provided.
>> WARNING
>> Line: 36
>> UNSAFE_CALL_ARGUMENT
>> The argument 1 of the function "float_func()" requires the subtype "float" but the supertype "Variant" was provided.
>> WARNING
>> Line: 37
>> UNSAFE_CALL_ARGUMENT
>> The argument 1 of the function "float_func()" requires the subtype "float" but the supertype "Variant" was provided.
>> WARNING
>> Line: 40
>> UNSAFE_CALL_ARGUMENT
>> The argument 1 of the function "node_func()" requires the subtype "Node" but the supertype "Variant" was provided.
>> WARNING
>> Line: 41
>> UNSAFE_CALL_ARGUMENT
>> The argument 1 of the function "node_func()" requires the subtype "Node" but the supertype "Object" was provided.
>> WARNING
>> Line: 47
>> UNSAFE_CALL_ARGUMENT
>> The argument 1 of the constructor "Callable()" requires the subtype "Object" but the supertype "Variant" was provided.
>> WARNING
>> Line: 49
>> UNSAFE_CALL_ARGUMENT
>> The argument 1 of the constructor "Dictionary()" requires the subtype "Dictionary" but the supertype "Variant" was provided.
>> WARNING
>> Line: 50
>> UNSAFE_CALL_ARGUMENT
>> The argument 1 of the constructor "Vector2()" requires the subtype "Vector2" or "Vector2i" but the supertype "Variant" was provided.
>> WARNING
>> Line: 51
>> UNSAFE_CALL_ARGUMENT
>> The argument 1 of the constructor "int()" requires the subtype "int", "bool", or "float" but the supertype "Variant" was provided.

View file

@ -0,0 +1,24 @@
# We don't want to execute it because of errors, just analyze.
func no_exec_test():
var weak_int = 1
print(weak_int as Variant) # No warning.
print(weak_int as int)
print(weak_int as Node)
var weak_node = Node.new()
print(weak_node as Variant) # No warning.
print(weak_node as int)
print(weak_node as Node)
var weak_variant = null
print(weak_variant as Variant) # No warning.
print(weak_variant as int)
print(weak_variant as Node)
var hard_variant: Variant = null
print(hard_variant as Variant) # No warning.
print(hard_variant as int)
print(hard_variant as Node)
func test():
pass

View file

@ -0,0 +1,33 @@
GDTEST_OK
>> WARNING
>> Line: 5
>> UNSAFE_CAST
>> Casting "Variant" to "int" is unsafe.
>> WARNING
>> Line: 6
>> UNSAFE_CAST
>> Casting "Variant" to "Node" is unsafe.
>> WARNING
>> Line: 10
>> UNSAFE_CAST
>> Casting "Variant" to "int" is unsafe.
>> WARNING
>> Line: 11
>> UNSAFE_CAST
>> Casting "Variant" to "Node" is unsafe.
>> WARNING
>> Line: 15
>> UNSAFE_CAST
>> Casting "Variant" to "int" is unsafe.
>> WARNING
>> Line: 16
>> UNSAFE_CAST
>> Casting "Variant" to "Node" is unsafe.
>> WARNING
>> Line: 20
>> UNSAFE_CAST
>> Casting "Variant" to "int" is unsafe.
>> WARNING
>> Line: 21
>> UNSAFE_CAST
>> Casting "Variant" to "Node" is unsafe.

View file

@ -0,0 +1,10 @@
# GH-72135
var _a
@warning_ignore("unused_private_class_variable")
var _b
@warning_ignore("unused_private_class_variable") var _c
var _d
func test():
pass

View file

@ -0,0 +1,9 @@
GDTEST_OK
>> WARNING
>> Line: 3
>> UNUSED_PRIVATE_CLASS_VARIABLE
>> The class variable "_a" is declared but never used in the class.
>> WARNING
>> Line: 7
>> UNUSED_PRIVATE_CLASS_VARIABLE
>> The class variable "_d" is declared but never used in the class.

View file

@ -0,0 +1,12 @@
signal s1()
signal s2()
signal s3()
@warning_ignore("unused_signal")
signal s4()
func no_exec():
s1.emit()
print(s2)
func test():
pass

View file

@ -0,0 +1,5 @@
GDTEST_OK
>> WARNING
>> Line: 3
>> UNUSED_SIGNAL
>> The signal "s3" is declared but never explicitly used in the class.