Merge pull request #84043 from dalexeev/gds-fix-unsafe-cast-warning

GDScript: Fix `UNSAFE_CAST` warning
This commit is contained in:
Rémi Verschelde 2024-04-09 22:24:55 +02:00
commit f8ca571efe
No known key found for this signature in database
GPG key ID: C3336907360768E1
22 changed files with 150 additions and 6 deletions

View file

@ -0,0 +1,4 @@
func test():
var node := Node.new()
node.free()
print(node as Node2D)

View file

@ -0,0 +1,6 @@
GDTEST_RUNTIME_ERROR
>> SCRIPT ERROR
>> on function: test()
>> runtime/errors/cast_freed_object.gd
>> 4
>> Trying to cast a freed object.

View file

@ -0,0 +1,4 @@
func test():
var integer: Variant = 1
@warning_ignore("unsafe_cast")
print(integer as Array)

View file

@ -0,0 +1,6 @@
GDTEST_RUNTIME_ERROR
>> SCRIPT ERROR
>> on function: test()
>> runtime/errors/cast_int_to_array.gd
>> 4
>> Invalid cast: could not convert value to 'Array'.

View file

@ -0,0 +1,4 @@
func test():
var integer: Variant = 1
@warning_ignore("unsafe_cast")
print(integer as Node)

View file

@ -0,0 +1,6 @@
GDTEST_RUNTIME_ERROR
>> SCRIPT ERROR
>> on function: test()
>> runtime/errors/cast_int_to_object.gd
>> 4
>> Invalid cast: can't convert a non-object value to an object type.

View file

@ -0,0 +1,4 @@
func test():
var object: Variant = RefCounted.new()
@warning_ignore("unsafe_cast")
print(object as int)

View file

@ -0,0 +1,6 @@
GDTEST_RUNTIME_ERROR
>> SCRIPT ERROR
>> on function: test()
>> runtime/errors/cast_object_to_int.gd
>> 4
>> Invalid cast: could not convert value to 'int'.