diff options
author | George Marques <george@gmarqu.es> | 2020-08-06 10:51:48 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-06 10:51:48 -0300 |
commit | 241e709462cd90d3daade3c6a05ff130fe85b4c0 (patch) | |
tree | 304d9cf7fa97522d3901467c3cb28baf64479e27 /modules/gdscript | |
parent | 6831da630f5609e1b659d65425d9da07e25df616 (diff) | |
parent | 38c7d080e8cad2e03ec3a1c0e77c1a1750de58f2 (diff) |
Merge pull request #41062 from ThakeeNathees/unsafe-arithmatic-assignment-bug-fix
GDScript: unsafe arithmetic assignment bug fix
Diffstat (limited to 'modules/gdscript')
-rw-r--r-- | modules/gdscript/gdscript_analyzer.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 531666bec5..e2daa8889f 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -1406,23 +1406,25 @@ void GDScriptAnalyzer::reduce_assignment(GDScriptParser::AssignmentNode *p_assig break; } - bool compatible = true; - GDScriptParser::DataType op_type = p_assignment->assigned_value->get_datatype(); - if (vop != Variant::OP_EQUAL) { - op_type = get_operation_type(vop, p_assignment->assignee->get_datatype(), p_assignment->assigned_value->get_datatype(), compatible); - } - - if (compatible) { - compatible = is_type_compatible(p_assignment->assignee->get_datatype(), op_type, true); - if (!compatible) { - if (p_assignment->assignee->get_datatype().is_hard_type()) { - push_error(vformat(R"(Cannot assign a value of type "%s" to a target of type "%s".)", p_assignment->assigned_value->get_datatype().to_string(), p_assignment->assignee->get_datatype().to_string()), p_assignment->assigned_value); - } else { - // TODO: Warning in this case. + if (!p_assignment->assignee->get_datatype().is_variant() && !p_assignment->assigned_value->get_datatype().is_variant()) { + bool compatible = true; + GDScriptParser::DataType op_type = p_assignment->assigned_value->get_datatype(); + if (vop != Variant::OP_EQUAL) { + op_type = get_operation_type(vop, p_assignment->assignee->get_datatype(), p_assignment->assigned_value->get_datatype(), compatible); + } + + if (compatible) { + compatible = is_type_compatible(p_assignment->assignee->get_datatype(), op_type, true); + if (!compatible) { + if (p_assignment->assignee->get_datatype().is_hard_type()) { + push_error(vformat(R"(Cannot assign a value of type "%s" to a target of type "%s".)", p_assignment->assigned_value->get_datatype().to_string(), p_assignment->assignee->get_datatype().to_string()), p_assignment->assigned_value); + } else { + // TODO: Warning in this case. + } } + } else { + push_error(vformat(R"(Invalid operands "%s" and "%s" for assignment operator.)", p_assignment->assignee->get_datatype().to_string(), p_assignment->assigned_value->get_datatype().to_string()), p_assignment); } - } else { - push_error(vformat(R"(Invalid operands "%s" and "%s" for assignment operator.)", p_assignment->assignee->get_datatype().to_string(), p_assignment->assigned_value->get_datatype().to_string()), p_assignment); } if (p_assignment->assignee->get_datatype().has_no_type() || p_assignment->assigned_value->get_datatype().is_variant()) { |