From eeaf5ebd88379ddb861f0d9f6b022737b8f6e44f Mon Sep 17 00:00:00 2001 From: rune-scape Date: Tue, 18 Jun 2024 04:21:22 -0700 Subject: [PATCH] Variant: add method `get_full_type_name` and used in many places --- core/math/expression.cpp | 6 +- core/variant/array.cpp | 12 +-- core/variant/container_type_validate.h | 43 ++++++++++- core/variant/variant.cpp | 74 ++++++++++++++++++- core/variant/variant.h | 1 + editor/animation_track_editor.cpp | 2 +- editor/connections_dialog.cpp | 2 +- .../debug_adapter/debug_adapter_protocol.cpp | 6 +- modules/gdscript/gdscript_analyzer.cpp | 8 +- modules/gdscript/gdscript_parser.cpp | 2 +- .../gdscript/gdscript_utility_functions.cpp | 2 +- modules/gdscript/gdscript_vm.cpp | 28 +++---- .../runtime/errors/global_base.notest.gd | 1 + .../runtime/errors/global_class_1.notest.gd | 1 + .../runtime/errors/global_class_2.notest.gd | 1 + .../typed_array_assign_wrong_to_typed.gd | 6 +- .../typed_array_assign_wrong_to_typed.out | 2 +- modules/gdscript/tests/test_gdscript.cpp | 2 +- .../editor/editor_import_blend_runner.cpp | 4 +- modules/mono/editor/bindings_generator.cpp | 12 +-- modules/mono/glue/runtime_interop.cpp | 2 +- scene/animation/tween.cpp | 2 +- scene/resources/theme.cpp | 12 +-- 23 files changed, 172 insertions(+), 59 deletions(-) create mode 100644 modules/gdscript/tests/scripts/runtime/errors/global_base.notest.gd create mode 100644 modules/gdscript/tests/scripts/runtime/errors/global_class_1.notest.gd create mode 100644 modules/gdscript/tests/scripts/runtime/errors/global_class_2.notest.gd diff --git a/core/math/expression.cpp b/core/math/expression.cpp index 35303fe9ac47..9d317a1b6613 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -1278,7 +1278,7 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: bool valid = true; Variant::evaluate(op->op, a, b, r_ret, valid); if (!valid) { - r_error_str = vformat(RTR("Invalid operands to operator %s, %s and %s."), Variant::get_operator_name(op->op), Variant::get_type_name(a.get_type()), Variant::get_type_name(b.get_type())); + r_error_str = vformat(RTR("Invalid operands to operator %s, %s and %s."), Variant::get_operator_name(op->op), a.get_full_type_name(), b.get_full_type_name()); return true; } @@ -1302,7 +1302,7 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: bool valid; r_ret = base.get(idx, &valid); if (!valid) { - r_error_str = vformat(RTR("Invalid index of type %s for base type %s"), Variant::get_type_name(idx.get_type()), Variant::get_type_name(base.get_type())); + r_error_str = vformat(RTR("Invalid index of type %s for base type %s"), idx.get_full_type_name(), base.get_full_type_name()); return true; } @@ -1319,7 +1319,7 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: bool valid; r_ret = base.get_named(index->name, valid); if (!valid) { - r_error_str = vformat(RTR("Invalid named index '%s' for base type %s"), String(index->name), Variant::get_type_name(base.get_type())); + r_error_str = vformat(RTR("Invalid named index '%s' for base type %s"), String(index->name), base.get_full_type_name()); return true; } diff --git a/core/variant/array.cpp b/core/variant/array.cpp index f7a86b8fa386..115147592710 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -235,14 +235,14 @@ void Array::assign(const Array &p_array) { for (int i = 0; i < size; i++) { const Variant &element = source[i]; if (element.get_type() != Variant::NIL && (element.get_type() != Variant::OBJECT || !typed.validate_object(element, "assign"))) { - ERR_FAIL_MSG(vformat(R"(Unable to convert array index %d from "%s" to "%s".)", i, Variant::get_type_name(element.get_type()), Variant::get_type_name(typed.type))); + ERR_FAIL_MSG(vformat(R"(Unable to convert array index %d from "%s" to "%s".)", i, element.get_full_type_name(), typed.get_contained_type_name())); } } _p->array = p_array._p->array; return; } if (typed.type == Variant::OBJECT || source_typed.type == Variant::OBJECT) { - ERR_FAIL_MSG(vformat(R"(Cannot assign contents of "Array[%s]" to "Array[%s]".)", Variant::get_type_name(source_typed.type), Variant::get_type_name(typed.type))); + ERR_FAIL_MSG(vformat(R"(Cannot assign contents of "Array[%s]" to "Array[%s]".)", source_typed.get_contained_type_name(), typed.get_contained_type_name())); } Vector array; @@ -258,11 +258,11 @@ void Array::assign(const Array &p_array) { continue; } if (!Variant::can_convert_strict(value->get_type(), typed.type)) { - ERR_FAIL_MSG(vformat(R"(Unable to convert array index %d from "%s" to "%s".)", i, Variant::get_type_name(value->get_type()), Variant::get_type_name(typed.type))); + ERR_FAIL_MSG(vformat(R"(Unable to convert array index %d from "%s" to "%s".)", i, value->get_full_type_name(), typed.get_contained_type_name())); } Callable::CallError ce; Variant::construct(typed.type, data[i], &value, 1, ce); - ERR_FAIL_COND_MSG(ce.error, vformat(R"(Unable to convert array index %d from "%s" to "%s".)", i, Variant::get_type_name(value->get_type()), Variant::get_type_name(typed.type))); + ERR_FAIL_COND_MSG(ce.error, vformat(R"(Unable to convert array index %d from "%s" to "%s".)", i, value->get_full_type_name(), typed.get_contained_type_name())); } } else if (Variant::can_convert_strict(source_typed.type, typed.type)) { // from primitives to different convertible primitives @@ -270,10 +270,10 @@ void Array::assign(const Array &p_array) { const Variant *value = source + i; Callable::CallError ce; Variant::construct(typed.type, data[i], &value, 1, ce); - ERR_FAIL_COND_MSG(ce.error, vformat(R"(Unable to convert array index %d from "%s" to "%s".)", i, Variant::get_type_name(value->get_type()), Variant::get_type_name(typed.type))); + ERR_FAIL_COND_MSG(ce.error, vformat(R"(Unable to convert array index %d from "%s" to "%s".)", i, value->get_full_type_name(), typed.get_contained_type_name())); } } else { - ERR_FAIL_MSG(vformat(R"(Cannot assign contents of "Array[%s]" to "Array[%s]".)", Variant::get_type_name(source_typed.type), Variant::get_type_name(typed.type))); + ERR_FAIL_MSG(vformat(R"(Cannot assign contents of "Array[%s]" to "Array[%s]".)", source_typed.get_contained_type_name(), typed.get_contained_type_name())); } _p->array = array; diff --git a/core/variant/container_type_validate.h b/core/variant/container_type_validate.h index 8971fadf7320..25fcc02cab87 100644 --- a/core/variant/container_type_validate.h +++ b/core/variant/container_type_validate.h @@ -34,12 +34,53 @@ #include "core/object/script_language.h" #include "core/variant/variant.h" +#include "modules/modules_enabled.gen.h" + +#ifdef MODULE_GDSCRIPT_ENABLED +#include "modules/gdscript/gdscript.h" +#endif // MODULE_GDSCRIPT_ENABLED + struct ContainerTypeValidate { Variant::Type type = Variant::NIL; StringName class_name; Ref