mirror of
https://github.com/godotengine/godot.git
synced 2024-11-27 09:16:35 +08:00
Merge pull request #15282 from poke1024/check-obj-class
Check implicit casts on object classes in bound method calls
This commit is contained in:
commit
06f1d1ae23
@ -128,10 +128,36 @@ struct VariantCaster<const T &> {
|
||||
// Object enum casts must go here
|
||||
VARIANT_ENUM_CAST(Object::ConnectFlags);
|
||||
|
||||
template <typename T>
|
||||
struct VariantObjectClassChecker {
|
||||
static _FORCE_INLINE_ bool check(const Variant &p_variant) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantObjectClassChecker<Node *> {
|
||||
static _FORCE_INLINE_ bool check(const Variant &p_variant) {
|
||||
Object *obj = p_variant;
|
||||
Node *node = p_variant;
|
||||
return node || !obj;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantObjectClassChecker<Control *> {
|
||||
static _FORCE_INLINE_ bool check(const Variant &p_variant) {
|
||||
Object *obj = p_variant;
|
||||
Control *control = p_variant;
|
||||
return control || !obj;
|
||||
}
|
||||
};
|
||||
|
||||
#define CHECK_ARG(m_arg) \
|
||||
if ((m_arg - 1) < p_arg_count) { \
|
||||
Variant::Type argtype = get_argument_type(m_arg - 1); \
|
||||
if (!Variant::can_convert_strict(p_args[m_arg - 1]->get_type(), argtype)) { \
|
||||
if (!Variant::can_convert_strict(p_args[m_arg - 1]->get_type(), argtype) || \
|
||||
!VariantObjectClassChecker<P##m_arg>::check(*p_args[m_arg - 1])) { \
|
||||
r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; \
|
||||
r_error.argument = m_arg - 1; \
|
||||
r_error.expected = argtype; \
|
||||
|
Loading…
Reference in New Issue
Block a user