Merge pull request #70702 from vnen/gdscript-error-on-assign-void

GDScript: Error when assigning return value of void function
This commit is contained in:
Rémi Verschelde
2023-01-03 12:23:00 +01:00
26 changed files with 108 additions and 53 deletions

View File

@ -0,0 +1,3 @@
func test():
var builtin := []
print(builtin.reverse()) # Built-in type method.

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot get return value of call to "reverse()" because it returns "void".

View File

@ -0,0 +1,5 @@
func foo() -> void:
pass
func test():
print(foo()) # Custom method.

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot get return value of call to "foo()" because it returns "void".

View File

@ -0,0 +1,2 @@
func test():
print(print_debug()) # GDScript utility function.

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot get return value of call to "print_debug()" because it returns "void".

View File

@ -0,0 +1,3 @@
func test():
var obj := Node.new()
print(obj.free()) # Native type method.

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot get return value of call to "free()" because it returns "void".

View File

@ -0,0 +1,2 @@
func test():
print(print()) # Built-in utility function.

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot get return value of call to "print()" because it returns "void".

View File

@ -1,6 +0,0 @@
func i_return_void() -> void:
return
func test():
var __ = i_return_void()

View File

@ -1,5 +0,0 @@
GDTEST_OK
>> WARNING
>> Line: 6
>> VOID_ASSIGNMENT
>> Assignment operation, but the function 'i_return_void()' returns void.

View File

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

View File

@ -0,0 +1,6 @@
GDTEST_RUNTIME_ERROR
>> SCRIPT ERROR
>> on function: test()
>> runtime/errors/use_return_value_of_free_call.gd
>> 4
>> Trying to get a return value of a method that returns "void"

View File

@ -0,0 +1,4 @@
func test():
var value
value = []
print(value.reverse())

View File

@ -0,0 +1,6 @@
GDTEST_RUNTIME_ERROR
>> SCRIPT ERROR
>> on function: test()
>> runtime/errors/use_return_value_of_void_builtin_method_call.gd
>> 4
>> Trying to get a return value of a method that returns "void"

View File

@ -0,0 +1,4 @@
func test():
var obj
obj = RefCounted.new()
print(obj.notify_property_list_changed())

View File

@ -0,0 +1,6 @@
GDTEST_RUNTIME_ERROR
>> SCRIPT ERROR
>> on function: test()
>> runtime/errors/use_return_value_of_void_native_method_call.gd
>> 4
>> Trying to get a return value of a method that returns "void"

View File

@ -15,10 +15,10 @@ func test():
var string_array: Array[String] = []
var stringname_array: Array[StringName] = []
assert(!string_array.push_back(&"abc"))
string_array.push_back(&"abc")
print("Array[String] insert converted: ", typeof(string_array[0]) == TYPE_STRING)
assert(!stringname_array.push_back("abc"))
stringname_array.push_back("abc")
print("Array[StringName] insert converted: ", typeof(stringname_array[0]) == TYPE_STRING_NAME)
print("StringName in Array[String]: ", &"abc" in string_array)
@ -28,8 +28,8 @@ func test():
assert(!packed_string_array.push_back("abc"))
print("StringName in PackedStringArray: ", &"abc" in packed_string_array)
assert(!string_array.push_back("abc"))
string_array.push_back("abc")
print("StringName finds String in Array: ", string_array.find(&"abc"))
assert(!stringname_array.push_back(&"abc"))
stringname_array.push_back(&"abc")
print("String finds StringName in Array: ", stringname_array.find("abc"))