summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDavid Sichma <david.sichma@student.kit.edu>2021-10-05 12:39:13 +0200
committerDavid Sichma <david.sichma@student.kit.edu>2021-10-08 23:54:55 +0200
commitd28f2ee7a5e0d8403bad27904221c67b0db91f52 (patch)
tree5c93cb61b4c7fec24ce27fa4279547dab11b1722 /modules
parent75d3a10a233f1ce412aba16eeee4038c4a7e587a (diff)
Only emit typed member setters if safe to do so
Instructions are now only emitted if input type matches expected type. Otherwise usual setter fallback.
Diffstat (limited to 'modules')
-rw-r--r--modules/gdscript/gdscript_byte_codegen.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/modules/gdscript/gdscript_byte_codegen.cpp b/modules/gdscript/gdscript_byte_codegen.cpp
index b8300cd872..6a7e4278d2 100644
--- a/modules/gdscript/gdscript_byte_codegen.cpp
+++ b/modules/gdscript/gdscript_byte_codegen.cpp
@@ -692,7 +692,8 @@ void GDScriptByteCodeGenerator::write_end_ternary() {
void GDScriptByteCodeGenerator::write_set(const Address &p_target, const Address &p_index, const Address &p_source) {
if (HAS_BUILTIN_TYPE(p_target)) {
- if (IS_BUILTIN_TYPE(p_index, Variant::INT) && Variant::get_member_validated_indexed_setter(p_target.type.builtin_type)) {
+ if (IS_BUILTIN_TYPE(p_index, Variant::INT) && Variant::get_member_validated_indexed_setter(p_target.type.builtin_type) &&
+ IS_BUILTIN_TYPE(p_source, Variant::get_indexed_element_type(p_target.type.builtin_type))) {
// Use indexed setter instead.
Variant::ValidatedIndexedSetter setter = Variant::get_member_validated_indexed_setter(p_target.type.builtin_type);
append(GDScriptFunction::OPCODE_SET_INDEXED_VALIDATED, 3);
@@ -746,7 +747,8 @@ void GDScriptByteCodeGenerator::write_get(const Address &p_target, const Address
}
void GDScriptByteCodeGenerator::write_set_named(const Address &p_target, const StringName &p_name, const Address &p_source) {
- if (HAS_BUILTIN_TYPE(p_target) && Variant::get_member_validated_setter(p_target.type.builtin_type, p_name)) {
+ if (HAS_BUILTIN_TYPE(p_target) && Variant::get_member_validated_setter(p_target.type.builtin_type, p_name) &&
+ IS_BUILTIN_TYPE(p_source, Variant::get_member_type(p_target.type.builtin_type, p_name))) {
Variant::ValidatedSetter setter = Variant::get_member_validated_setter(p_target.type.builtin_type, p_name);
append(GDScriptFunction::OPCODE_SET_NAMED_VALIDATED, 2);
append(p_target);