From aee7b7363b206678816272f1bd43b192cdc7d12a Mon Sep 17 00:00:00 2001 From: George Marques Date: Sat, 28 Jan 2023 20:33:01 -0300 Subject: [PATCH] GDScript: Avoid calling non-static methods on native classes --- modules/gdscript/gdscript.cpp | 2 +- .../errors/non_static_method_call_on_native_class.gd | 6 ++++++ .../errors/non_static_method_call_on_native_class.out | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 modules/gdscript/tests/scripts/runtime/errors/non_static_method_call_on_native_class.gd create mode 100644 modules/gdscript/tests/scripts/runtime/errors/non_static_method_call_on_native_class.out diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 4fc3929bbd0..d9b8a540c08 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -98,7 +98,7 @@ Variant GDScriptNativeClass::callp(const StringName &p_method, const Variant **p return Object::callp(p_method, p_args, p_argcount, r_error); } MethodBind *method = ClassDB::get_method(name, p_method); - if (method) { + if (method && method->is_static()) { // Native static method. return method->call(nullptr, p_args, p_argcount, r_error); } diff --git a/modules/gdscript/tests/scripts/runtime/errors/non_static_method_call_on_native_class.gd b/modules/gdscript/tests/scripts/runtime/errors/non_static_method_call_on_native_class.gd new file mode 100644 index 00000000000..0c15701364e --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/non_static_method_call_on_native_class.gd @@ -0,0 +1,6 @@ +# https://github.com/godotengine/godot/issues/66675 +func test(): + example(Node2D) + +func example(thing): + print(thing.has_method('asdf')) diff --git a/modules/gdscript/tests/scripts/runtime/errors/non_static_method_call_on_native_class.out b/modules/gdscript/tests/scripts/runtime/errors/non_static_method_call_on_native_class.out new file mode 100644 index 00000000000..3a90f98d999 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/non_static_method_call_on_native_class.out @@ -0,0 +1,6 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: example() +>> runtime/errors/non_static_method_call_on_native_class.gd +>> 6 +>> Invalid call. Nonexistent function 'has_method' in base 'Node2D'.