[GDScript] Correctly report invalid read-only access

This commit is contained in:
A Thousand Ships 2024-03-18 14:42:42 +01:00
parent 26738ea20d
commit c4e24d2b3b
No known key found for this signature in database
GPG key ID: 2033189A662F8BD7
6 changed files with 64 additions and 36 deletions

View file

@ -3515,6 +3515,17 @@ bool Variant::is_shared() const {
return is_type_shared(type);
}
bool Variant::is_read_only() const {
switch (type) {
case ARRAY:
return reinterpret_cast<const Array *>(_data._mem)->is_read_only();
case DICTIONARY:
return reinterpret_cast<const Dictionary *>(_data._mem)->is_read_only();
default:
return false;
}
}
void Variant::_variant_call_error(const String &p_method, Callable::CallError &error) {
switch (error.error) {
case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT: {

View file

@ -349,6 +349,7 @@ public:
bool is_zero() const;
bool is_one() const;
bool is_null() const;
bool is_read_only() const;
// Make sure Variant is not implicitly cast when accessing it with bracket notation (GH-49469).
Variant &operator[](const Variant &p_key) = delete;