Fix inability to assign null regression

Co-authored-by: Dmitry Maganov <vonagam@gmail.com>
This commit is contained in:
ocean (they/them) 2023-02-17 09:25:57 -05:00
parent 6e0dd6beca
commit 9eb4d1e4bf
3 changed files with 35 additions and 19 deletions

View file

@ -1245,21 +1245,19 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE_BREAK; OPCODE_BREAK;
} }
bool was_freed = false; if (src->get_type() == Variant::OBJECT) {
Object *src_obj = src->get_validated_object_with_check(was_freed); bool was_freed = false;
if (!src_obj) { Object *src_obj = src->get_validated_object_with_check(was_freed);
if (was_freed) { if (!src_obj && was_freed) {
err_text = "Trying to assign invalid previously freed instance."; err_text = "Trying to assign invalid previously freed instance.";
} else { OPCODE_BREAK;
err_text = "Trying to assign invalid null variable.";
} }
OPCODE_BREAK;
}
if (src_obj && !ClassDB::is_parent_class(src_obj->get_class_name(), nc->get_name())) { if (src_obj && !ClassDB::is_parent_class(src_obj->get_class_name(), nc->get_name())) {
err_text = "Trying to assign value of type '" + src_obj->get_class_name() + err_text = "Trying to assign value of type '" + src_obj->get_class_name() +
"' to a variable of type '" + nc->get_name() + "'."; "' to a variable of type '" + nc->get_name() + "'.";
OPCODE_BREAK; OPCODE_BREAK;
}
} }
#endif // DEBUG_ENABLED #endif // DEBUG_ENABLED
*dst = *src; *dst = *src;
@ -1284,15 +1282,11 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODE_BREAK; OPCODE_BREAK;
} }
if (src->get_type() != Variant::NIL) { if (src->get_type() == Variant::OBJECT) {
bool was_freed = false; bool was_freed = false;
Object *val_obj = src->get_validated_object_with_check(was_freed); Object *val_obj = src->get_validated_object_with_check(was_freed);
if (!val_obj) { if (!val_obj && was_freed) {
if (was_freed) { err_text = "Trying to assign invalid previously freed instance.";
err_text = "Trying to assign invalid previously freed instance.";
} else {
err_text = "Trying to assign invalid null variable.";
}
OPCODE_BREAK; OPCODE_BREAK;
} }

View file

@ -0,0 +1,15 @@
extends Node
func test():
var typed: Variant = get_node_or_null("does_not_exist")
var untyped = null
var node_1: Node = typed
var node_2: Node = untyped
var node_3 = typed
var node_4 = untyped
print(typed)
print(untyped)
print(node_1)
print(node_2)
print(node_3)
print(node_4)

View file

@ -0,0 +1,7 @@
GDTEST_OK
<Object#null>
<null>
<Object#null>
<null>
<Object#null>
<null>