diff options
author | Yuri Sizov <11782833+YuriSizov@users.noreply.github.com> | 2023-02-18 04:38:47 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-18 04:38:47 +0300 |
commit | 78cd5d813b43c397552df777a86c33ecdd903a4e (patch) | |
tree | b9ec902c8d907c89ad65cb7a39a6b7b242df1310 /modules | |
parent | ed8554bff65b57e987a16050cb91d9252ab93da5 (diff) | |
parent | 9eb4d1e4bff23a4ea80af606a9bbfff1a884e221 (diff) |
Merge pull request #73501 from anvilfolk/oopsiedaisy
Fix inability to assign null regression
Diffstat (limited to 'modules')
3 files changed, 35 insertions, 19 deletions
diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp index fd8875d8b1..9f7d27d841 100644 --- a/modules/gdscript/gdscript_vm.cpp +++ b/modules/gdscript/gdscript_vm.cpp @@ -1275,21 +1275,19 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a OPCODE_BREAK; } - bool was_freed = false; - Object *src_obj = src->get_validated_object_with_check(was_freed); - if (!src_obj) { - if (was_freed) { + if (src->get_type() == Variant::OBJECT) { + bool was_freed = false; + Object *src_obj = src->get_validated_object_with_check(was_freed); + if (!src_obj && was_freed) { err_text = "Trying to assign invalid previously freed instance."; - } else { - err_text = "Trying to assign invalid null variable."; + OPCODE_BREAK; } - OPCODE_BREAK; - } - 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() + - "' to a variable of type '" + nc->get_name() + "'."; - OPCODE_BREAK; + 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() + + "' to a variable of type '" + nc->get_name() + "'."; + OPCODE_BREAK; + } } #endif // DEBUG_ENABLED *dst = *src; @@ -1314,15 +1312,11 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a OPCODE_BREAK; } - if (src->get_type() != Variant::NIL) { + if (src->get_type() == Variant::OBJECT) { bool was_freed = false; Object *val_obj = src->get_validated_object_with_check(was_freed); - if (!val_obj) { - if (was_freed) { - err_text = "Trying to assign invalid previously freed instance."; - } else { - err_text = "Trying to assign invalid null variable."; - } + if (!val_obj && was_freed) { + err_text = "Trying to assign invalid previously freed instance."; OPCODE_BREAK; } diff --git a/modules/gdscript/tests/scripts/analyzer/features/native_typed_assign_null.gd b/modules/gdscript/tests/scripts/analyzer/features/native_typed_assign_null.gd new file mode 100644 index 0000000000..c197062d9f --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/native_typed_assign_null.gd @@ -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) diff --git a/modules/gdscript/tests/scripts/analyzer/features/native_typed_assign_null.out b/modules/gdscript/tests/scripts/analyzer/features/native_typed_assign_null.out new file mode 100644 index 0000000000..d66b72f5c3 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/native_typed_assign_null.out @@ -0,0 +1,7 @@ +GDTEST_OK +<Object#null> +<null> +<Object#null> +<null> +<Object#null> +<null> |