summaryrefslogtreecommitdiff
path: root/modules/gdscript
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-02-20 15:41:40 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-02-20 15:41:40 +0100
commitea2bc9795c46ebb705c72add7a30ffeb59ff7922 (patch)
tree03debb75c127701a60214f3e48153ee21ff02ca1 /modules/gdscript
parent561d9497399db6136a6cbac17d7736222039cf6a (diff)
parent30d4d3fa5ec241dd24b25910621bace9427202d0 (diff)
Merge pull request #73544 from mashumafi/fix-func-arg-null
Fix: Func with typed args error when arg is null
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/gdscript_function.h10
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/typed_argument_is_null.gd27
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/typed_argument_is_null.out3
3 files changed, 36 insertions, 4 deletions
diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h
index 993d9f27d9..1a5e9eef53 100644
--- a/modules/gdscript/gdscript_function.h
+++ b/modules/gdscript/gdscript_function.h
@@ -105,9 +105,10 @@ public:
return false;
}
- Object *obj = p_variant.get_validated_object();
+ bool was_freed = false;
+ Object *obj = p_variant.get_validated_object_with_check(was_freed);
if (!obj) {
- return false;
+ return !was_freed;
}
if (!ClassDB::is_parent_class(obj->get_class_name(), native_type)) {
@@ -124,9 +125,10 @@ public:
return false;
}
- Object *obj = p_variant.get_validated_object();
+ bool was_freed = false;
+ Object *obj = p_variant.get_validated_object_with_check(was_freed);
if (!obj) {
- return false;
+ return !was_freed;
}
Ref<Script> base = obj && obj->get_script_instance() ? obj->get_script_instance()->get_script() : nullptr;
diff --git a/modules/gdscript/tests/scripts/runtime/features/typed_argument_is_null.gd b/modules/gdscript/tests/scripts/runtime/features/typed_argument_is_null.gd
new file mode 100644
index 0000000000..277242156d
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/typed_argument_is_null.gd
@@ -0,0 +1,27 @@
+# https://github.com/godotengine/godot/issues/72967
+
+class CustomNode:
+ extends Node
+
+ static func test_custom_node(n: CustomNode):
+ if not n:
+ print("null node")
+
+func test():
+ test_typed_argument_is_null()
+
+func get_custom_node() -> CustomNode:
+ return null
+
+func test_typed_argument_is_null():
+ var node: Node = Node.new()
+ print_node_name(node.get_parent())
+ node.free()
+ test_custom_node()
+
+func test_custom_node():
+ CustomNode.test_custom_node(get_custom_node())
+
+func print_node_name(n: Node):
+ if not n:
+ print("null node")
diff --git a/modules/gdscript/tests/scripts/runtime/features/typed_argument_is_null.out b/modules/gdscript/tests/scripts/runtime/features/typed_argument_is_null.out
new file mode 100644
index 0000000000..41560003d6
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/typed_argument_is_null.out
@@ -0,0 +1,3 @@
+GDTEST_OK
+null node
+null node