You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
GDScript: Improve usability of setter chains
- Consider PackedArrays non-shared since they are copied on C++/script boundaries. - Add error messages in the analyzer when assigning to read-only properties. - Add specific error message at runtime when assignment fails because the property is read-only.
This commit is contained in:
@@ -811,13 +811,22 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (!valid) {
|
||||
Object *obj = dst->get_validated_object();
|
||||
String v = index->operator String();
|
||||
if (!v.is_empty()) {
|
||||
v = "'" + v + "'";
|
||||
} else {
|
||||
v = "of type '" + _get_var_type(index) + "'";
|
||||
bool read_only_property = false;
|
||||
if (obj) {
|
||||
read_only_property = ClassDB::has_property(obj->get_class_name(), v) && (ClassDB::get_property_setter(obj->get_class_name(), v) == StringName());
|
||||
}
|
||||
if (read_only_property) {
|
||||
err_text = vformat(R"(Cannot set value into property "%s" (on base "%s") because it is read-only.)", v, _get_var_type(dst));
|
||||
} else {
|
||||
if (!v.is_empty()) {
|
||||
v = "'" + v + "'";
|
||||
} else {
|
||||
v = "of type '" + _get_var_type(index) + "'";
|
||||
}
|
||||
err_text = "Invalid set index " + v + " (on base: '" + _get_var_type(dst) + "') with value of type '" + _get_var_type(value) + "'";
|
||||
}
|
||||
err_text = "Invalid set index " + v + " (on base: '" + _get_var_type(dst) + "') with value of type '" + _get_var_type(value) + "'";
|
||||
OPCODE_BREAK;
|
||||
}
|
||||
#endif
|
||||
@@ -1003,8 +1012,16 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (!valid) {
|
||||
String err_type;
|
||||
err_text = "Invalid set index '" + String(*index) + "' (on base: '" + _get_var_type(dst) + "') with value of type '" + _get_var_type(value) + "'.";
|
||||
Object *obj = dst->get_validated_object();
|
||||
bool read_only_property = false;
|
||||
if (obj) {
|
||||
read_only_property = ClassDB::has_property(obj->get_class_name(), *index) && (ClassDB::get_property_setter(obj->get_class_name(), *index) == StringName());
|
||||
}
|
||||
if (read_only_property) {
|
||||
err_text = vformat(R"(Cannot set value into property "%s" (on base "%s") because it is read-only.)", String(*index), _get_var_type(dst));
|
||||
} else {
|
||||
err_text = "Invalid set index '" + String(*index) + "' (on base: '" + _get_var_type(dst) + "') with value of type '" + _get_var_type(value) + "'.";
|
||||
}
|
||||
OPCODE_BREAK;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user