Allow primitives to be compared to Object types with is

This commit is contained in:
George Marques 2018-11-17 22:41:08 -02:00
parent 9eb4b6d91a
commit 0bc953d83b
No known key found for this signature in database
GPG key ID: 046BD46A3201E43D

View file

@ -477,24 +477,20 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GET_VARIANT_PTR(dst, 3); GET_VARIANT_PTR(dst, 3);
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
if (a->get_type() != Variant::OBJECT || a->operator Object *() == NULL) {
err_text = "Left operand of 'is' is not an instance of anything.";
OPCODE_BREAK;
}
if (b->get_type() != Variant::OBJECT || b->operator Object *() == NULL) { if (b->get_type() != Variant::OBJECT || b->operator Object *() == NULL) {
err_text = "Right operand of 'is' is not a class."; err_text = "Right operand of 'is' is not a class.";
OPCODE_BREAK; OPCODE_BREAK;
} }
#endif #endif
bool extends_ok = false;
if (a->get_type() == Variant::OBJECT && a->operator Object *() != NULL) {
Object *obj_A = *a; Object *obj_A = *a;
Object *obj_B = *b; Object *obj_B = *b;
GDScript *scr_B = Object::cast_to<GDScript>(obj_B); GDScript *scr_B = Object::cast_to<GDScript>(obj_B);
bool extends_ok = false;
if (scr_B) { if (scr_B) {
//if B is a script, the only valid condition is that A has an instance which inherits from the script //if B is a script, the only valid condition is that A has an instance which inherits from the script
//in other situation, this shoul return false. //in other situation, this shoul return false.
@ -528,6 +524,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
#endif #endif
extends_ok = ClassDB::is_parent_class(obj_A->get_class_name(), nc->get_name()); extends_ok = ClassDB::is_parent_class(obj_A->get_class_name(), nc->get_name());
} }
}
*dst = extends_ok; *dst = extends_ok;
ip += 4; ip += 4;