diff options
author | George Marques <george@gmarqu.es> | 2018-07-25 13:12:07 -0300 |
---|---|---|
committer | George Marques <george@gmarqu.es> | 2018-07-25 20:50:12 -0300 |
commit | 1ac9c0fe3aa42458441cea9ca9df87bde30e676a (patch) | |
tree | 6654e7204d227c64d8dc1fbcf93bb22bcc5b73c2 /modules | |
parent | 96ee93e8c7638d8c0d8f1dd6567bbab2a24fd9e8 (diff) |
GDScript: Allow strict conversion when assigning typed variables
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdscript/gdscript_function.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp index 6561071c5d..1e0363c2df 100644 --- a/modules/gdscript/gdscript_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -743,13 +743,18 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a GD_ERR_BREAK(var_type < 0 || var_type >= Variant::VARIANT_MAX); if (src->get_type() != var_type) { - err_text = "Trying to assign value of type '" + Variant::get_type_name(src->get_type()) + - "' to a variable of type '" + Variant::get_type_name(var_type) + "'."; - OPCODE_BREAK; + if (Variant::can_convert_strict(src->get_type(), var_type)) { + Variant::CallError ce; + *dst = Variant::construct(var_type, const_cast<const Variant **>(&src), 1, ce); + } else { + err_text = "Trying to assign value of type '" + Variant::get_type_name(src->get_type()) + + "' to a variable of type '" + Variant::get_type_name(var_type) + "'."; + OPCODE_BREAK; + } + } else { + *dst = *src; } - *dst = *src; - ip += 4; } DISPATCH_OPCODE; |