1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

GDScript: Error when assigning return value of void function

This also makes built-in method calls empty the return value when the
method is void, to avoid keeping returning a garbage value in such case.
This commit is contained in:
George Marques
2022-12-29 08:57:41 -03:00
parent b6e06038f8
commit 0c15844551
10 changed files with 70 additions and 18 deletions

View File

@@ -1533,8 +1533,28 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
Callable::CallError err;
if (call_ret) {
GET_INSTRUCTION_ARG(ret, argc + 1);
#ifdef DEBUG_ENABLED
Variant::Type base_type = base->get_type();
Object *base_obj = base->get_validated_object();
StringName base_class = base_obj ? base_obj->get_class_name() : StringName();
#endif
base->callp(*methodname, (const Variant **)argptrs, argc, *ret, err);
#ifdef DEBUG_ENABLED
if (ret->get_type() == Variant::NIL) {
if (base_type == Variant::OBJECT) {
if (base_obj) {
MethodBind *method = ClassDB::get_method(base_class, *methodname);
if (*methodname == CoreStringNames::get_singleton()->_free || (method && !method->has_return())) {
err_text = R"(Trying to get a return value of a method that returns "void")";
OPCODE_BREAK;
}
}
} else if (Variant::has_builtin_method(base_type, *methodname) && !Variant::has_builtin_method_return_value(base_type, *methodname)) {
err_text = R"(Trying to get a return value of a method that returns "void")";
OPCODE_BREAK;
}
}
if (!call_async && ret->get_type() == Variant::OBJECT) {
// Check if getting a function state without await.
bool was_freed = false;