Allow parameters passed to GDScript functions to be nulled

Previous version resulted in confusing (but actually right) errors about converting "from Object to Object", since CallError
does not include information about the actual types involved.
This commit is contained in:
Bojidar Marinov 2019-03-03 15:24:06 +02:00
parent e930fb9a6e
commit f0efc7521e
No known key found for this signature in database
GPG Key ID: 4B0FD31949AD430D
1 changed files with 9 additions and 4 deletions

View File

@ -329,10 +329,15 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
}
if (!argument_types[i].is_type(*p_args[i], true)) {
r_err.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_err.argument = i;
r_err.expected = argument_types[i].kind == GDScriptDataType::BUILTIN ? argument_types[i].builtin_type : Variant::OBJECT;
return Variant();
if (argument_types[i].is_type(Variant(), true)) {
memnew_placement(&stack[i], Variant);
continue;
} else {
r_err.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_err.argument = i;
r_err.expected = argument_types[i].kind == GDScriptDataType::BUILTIN ? argument_types[i].builtin_type : Variant::OBJECT;
return Variant();
}
}
if (argument_types[i].kind == GDScriptDataType::BUILTIN) {
Variant arg = Variant::construct(argument_types[i].builtin_type, &p_args[i], 1, r_err);