mirror of
https://github.com/godotengine/godot.git
synced 2024-11-22 12:12:28 +00:00
[Core] Fix property access on read-only Dictionary
This commit is contained in:
parent
7529c0bec5
commit
ec29c3e784
@ -251,15 +251,21 @@ void Variant::set_named(const StringName &p_member, const Variant &p_value, bool
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (type == Variant::DICTIONARY) {
|
} else if (type == Variant::DICTIONARY) {
|
||||||
Variant *v = VariantGetInternalPtr<Dictionary>::get_ptr(this)->getptr(p_member);
|
Dictionary &dict = *VariantGetInternalPtr<Dictionary>::get_ptr(this);
|
||||||
if (v) {
|
|
||||||
*v = p_value;
|
if (dict.is_read_only()) {
|
||||||
r_valid = true;
|
r_valid = false;
|
||||||
} else {
|
return;
|
||||||
VariantGetInternalPtr<Dictionary>::get_ptr(this)->operator[](p_member) = p_value;
|
|
||||||
r_valid = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Variant *v = dict.getptr(p_member);
|
||||||
|
if (v) {
|
||||||
|
*v = p_value;
|
||||||
|
} else {
|
||||||
|
dict[p_member] = p_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
r_valid = true;
|
||||||
} else {
|
} else {
|
||||||
r_valid = false;
|
r_valid = false;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
func test():
|
||||||
|
var dictionary := { "a": 0 }
|
||||||
|
dictionary.make_read_only()
|
||||||
|
dictionary.a = 1
|
@ -0,0 +1,6 @@
|
|||||||
|
GDTEST_RUNTIME_ERROR
|
||||||
|
>> SCRIPT ERROR
|
||||||
|
>> on function: test()
|
||||||
|
>> runtime/errors/read_only_dictionary.gd
|
||||||
|
>> 4
|
||||||
|
>> Invalid assignment of property or key 'a' with value of type 'int' on a base object of type 'Dictionary'.
|
Loading…
Reference in New Issue
Block a user