summaryrefslogtreecommitdiff
path: root/core/variant
diff options
context:
space:
mode:
Diffstat (limited to 'core/variant')
-rw-r--r--core/variant/variant.h4
-rw-r--r--core/variant/variant_op.cpp7
2 files changed, 9 insertions, 2 deletions
diff --git a/core/variant/variant.h b/core/variant/variant.h
index b2f31a6d57..f694e59051 100644
--- a/core/variant/variant.h
+++ b/core/variant/variant.h
@@ -346,6 +346,10 @@ public:
bool is_one() const;
bool is_null() const;
+ // Make sure Variant is not implicitly cast when accessing it with bracket notation (GH-49469).
+ Variant &operator[](const Variant &p_key) = delete;
+ const Variant &operator[](const Variant &p_key) const = delete;
+
operator bool() const;
operator signed int() const;
operator unsigned int() const; // this is the real one
diff --git a/core/variant/variant_op.cpp b/core/variant/variant_op.cpp
index 59f562865d..33c285dc6d 100644
--- a/core/variant/variant_op.cpp
+++ b/core/variant/variant_op.cpp
@@ -1105,8 +1105,11 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
evaluate(OP_IN, p_index, *this, ret, valid);
if (r_valid) {
*r_valid = valid;
+ }
+ if (valid) {
+ ERR_FAIL_COND_V(ret.type != BOOL, false);
+ return *VariantGetInternalPtr<bool>::get_ptr(&ret);
+ } else {
return false;
}
- ERR_FAIL_COND_V(ret.type != BOOL, false);
- return *VariantGetInternalPtr<bool>::get_ptr(&ret);
}