GDScript: Fix type detection on Object typed assign
Also make typed assigns a debug-only thing, so release builds are more lenient on errors.
This commit is contained in:
parent
a3ae4a9510
commit
aeb0b3114d
1 changed files with 14 additions and 3 deletions
|
|
@ -742,6 +742,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
||||||
|
|
||||||
GD_ERR_BREAK(var_type < 0 || var_type >= Variant::VARIANT_MAX);
|
GD_ERR_BREAK(var_type < 0 || var_type >= Variant::VARIANT_MAX);
|
||||||
|
|
||||||
|
#ifdef DEBUG_ENABLED
|
||||||
if (src->get_type() != var_type) {
|
if (src->get_type() != var_type) {
|
||||||
if (Variant::can_convert_strict(src->get_type(), var_type)) {
|
if (Variant::can_convert_strict(src->get_type(), var_type)) {
|
||||||
Variant::CallError ce;
|
Variant::CallError ce;
|
||||||
|
|
@ -752,8 +753,11 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
||||||
OPCODE_BREAK;
|
OPCODE_BREAK;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
#endif // DEBUG_ENABLED
|
||||||
*dst = *src;
|
*dst = *src;
|
||||||
|
#ifdef DEBUG_ENABLED
|
||||||
}
|
}
|
||||||
|
#endif // DEBUG_ENABLED
|
||||||
|
|
||||||
ip += 4;
|
ip += 4;
|
||||||
}
|
}
|
||||||
|
|
@ -766,17 +770,22 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
||||||
GET_VARIANT_PTR(dst, 2);
|
GET_VARIANT_PTR(dst, 2);
|
||||||
GET_VARIANT_PTR(src, 3);
|
GET_VARIANT_PTR(src, 3);
|
||||||
|
|
||||||
|
#ifdef DEBUG_ENABLED
|
||||||
GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(type->operator Object *());
|
GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(type->operator Object *());
|
||||||
GD_ERR_BREAK(!nc);
|
GD_ERR_BREAK(!nc);
|
||||||
|
if (!src->get_type() != Variant::OBJECT && !src->get_type() != Variant::NIL) {
|
||||||
|
err_text = "Trying to assign value of type '" + Variant::get_type_name(src->get_type()) +
|
||||||
|
"' to a variable of type '" + nc->get_name() + "'.";
|
||||||
|
OPCODE_BREAK;
|
||||||
|
}
|
||||||
Object *src_obj = src->operator Object *();
|
Object *src_obj = src->operator Object *();
|
||||||
GD_ERR_BREAK(!src_obj);
|
|
||||||
|
|
||||||
if (!ClassDB::is_parent_class(src_obj->get_class_name(), nc->get_name())) {
|
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() +
|
err_text = "Trying to assign value of type '" + src_obj->get_class_name() +
|
||||||
"' to a variable of type '" + nc->get_name() + "'.";
|
"' to a variable of type '" + nc->get_name() + "'.";
|
||||||
OPCODE_BREAK;
|
OPCODE_BREAK;
|
||||||
}
|
}
|
||||||
|
#endif // DEBUG_ENABLED
|
||||||
*dst = *src;
|
*dst = *src;
|
||||||
|
|
||||||
ip += 4;
|
ip += 4;
|
||||||
|
|
@ -790,6 +799,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
||||||
GET_VARIANT_PTR(dst, 2);
|
GET_VARIANT_PTR(dst, 2);
|
||||||
GET_VARIANT_PTR(src, 3);
|
GET_VARIANT_PTR(src, 3);
|
||||||
|
|
||||||
|
#ifdef DEBUG_ENABLED
|
||||||
Script *base_type = Object::cast_to<Script>(type->operator Object *());
|
Script *base_type = Object::cast_to<Script>(type->operator Object *());
|
||||||
|
|
||||||
GD_ERR_BREAK(!base_type);
|
GD_ERR_BREAK(!base_type);
|
||||||
|
|
@ -825,6 +835,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
||||||
OPCODE_BREAK;
|
OPCODE_BREAK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // DEBUG_ENABLED
|
||||||
|
|
||||||
*dst = *src;
|
*dst = *src;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue