Merge pull request #95166 from aaronp64/variant_op_err_return

Assign return value on `Variant` operator failure
This commit is contained in:
Rémi Verschelde 2024-09-23 12:27:51 +02:00
commit 1b19ecb360
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 24 additions and 6 deletions

View File

@ -923,7 +923,10 @@ public:
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
bool valid = true; bool valid = true;
String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), &valid); String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), &valid);
ERR_FAIL_COND_MSG(!valid, result); if (unlikely(!valid)) {
*VariantGetInternalPtr<String>::get_ptr(r_ret) = *VariantGetInternalPtr<S>::get_ptr(left);
ERR_FAIL_MSG(vformat("String formatting error: %s.", result));
}
*VariantGetInternalPtr<String>::get_ptr(r_ret) = result; *VariantGetInternalPtr<String>::get_ptr(r_ret) = result;
} }
static void ptr_evaluate(const void *left, const void *right, void *r_ret) { static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
@ -948,7 +951,10 @@ public:
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
bool valid = true; bool valid = true;
String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), *VariantGetInternalPtr<Array>::get_ptr(right), &valid); String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), *VariantGetInternalPtr<Array>::get_ptr(right), &valid);
ERR_FAIL_COND_MSG(!valid, result); if (unlikely(!valid)) {
*VariantGetInternalPtr<String>::get_ptr(r_ret) = *VariantGetInternalPtr<S>::get_ptr(left);
ERR_FAIL_MSG(vformat("String formatting error: %s.", result));
}
*VariantGetInternalPtr<String>::get_ptr(r_ret) = result; *VariantGetInternalPtr<String>::get_ptr(r_ret) = result;
} }
static void ptr_evaluate(const void *left, const void *right, void *r_ret) { static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
@ -976,7 +982,10 @@ public:
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
bool valid = true; bool valid = true;
String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), right->get_validated_object(), &valid); String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), right->get_validated_object(), &valid);
ERR_FAIL_COND_MSG(!valid, result); if (unlikely(!valid)) {
*VariantGetInternalPtr<String>::get_ptr(r_ret) = *VariantGetInternalPtr<S>::get_ptr(left);
ERR_FAIL_MSG(vformat("String formatting error: %s.", result));
}
*VariantGetInternalPtr<String>::get_ptr(r_ret) = result; *VariantGetInternalPtr<String>::get_ptr(r_ret) = result;
} }
static void ptr_evaluate(const void *left, const void *right, void *r_ret) { static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
@ -1003,7 +1012,10 @@ public:
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
bool valid = true; bool valid = true;
String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), *VariantGetInternalPtr<T>::get_ptr(right), &valid); String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), *VariantGetInternalPtr<T>::get_ptr(right), &valid);
ERR_FAIL_COND_MSG(!valid, result); if (unlikely(!valid)) {
*VariantGetInternalPtr<String>::get_ptr(r_ret) = *VariantGetInternalPtr<S>::get_ptr(left);
ERR_FAIL_MSG(vformat("String formatting error: %s.", result));
}
*VariantGetInternalPtr<String>::get_ptr(r_ret) = result; *VariantGetInternalPtr<String>::get_ptr(r_ret) = result;
} }
static void ptr_evaluate(const void *left, const void *right, void *r_ret) { static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
@ -1492,7 +1504,10 @@ public:
} }
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
Object *l = right->get_validated_object(); Object *l = right->get_validated_object();
ERR_FAIL_NULL(l); if (unlikely(!l)) {
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = false;
ERR_FAIL_MSG("Invalid base object for 'in'.");
}
const String &a = *VariantGetInternalPtr<String>::get_ptr(left); const String &a = *VariantGetInternalPtr<String>::get_ptr(left);
bool valid; bool valid;
@ -1526,7 +1541,10 @@ public:
} }
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
Object *l = right->get_validated_object(); Object *l = right->get_validated_object();
ERR_FAIL_NULL(l); if (unlikely(!l)) {
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = false;
ERR_FAIL_MSG("Invalid base object for 'in'.");
}
const StringName &a = *VariantGetInternalPtr<StringName>::get_ptr(left); const StringName &a = *VariantGetInternalPtr<StringName>::get_ptr(left);
bool valid; bool valid;