summaryrefslogtreecommitdiffstats
path: root/modules/gdscript
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-04-25 16:17:02 +0200
committerRémi Verschelde <rverschelde@gmail.com>2023-04-25 16:17:02 +0200
commit45cd5dcad39274da18440d6ea3c2121bec248eaa (patch)
treea750774d0366761fea401da3a3a74123e6c34a46 /modules/gdscript
parentefb42c3101a12120fb85ea6b5a1c03192591b152 (diff)
parente5365da03ca9dbd52b686174ff2defa0eca62803 (diff)
downloadredot-engine-45cd5dcad39274da18440d6ea3c2121bec248eaa.tar.gz
Merge pull request #75885 from AThousandShips/compound_fix
[GDScript] Fix incorrect compound assignment
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/gdscript_compiler.cpp12
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/assign_operator.gd31
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/assign_operator.out6
3 files changed, 38 insertions, 11 deletions
diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp
index 9e5c83d08c..42619a12a8 100644
--- a/modules/gdscript/gdscript_compiler.cpp
+++ b/modules/gdscript/gdscript_compiler.cpp
@@ -1165,18 +1165,8 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
bool has_operation = assignment->operation != GDScriptParser::AssignmentNode::OP_NONE;
if (has_operation) {
// Perform operation.
- GDScriptCodeGenerator::Address og_value = _parse_expression(codegen, r_error, assignment->assignee);
-
- if (!has_setter && !assignment->use_conversion_assign) {
- // If there's nothing special about the assignment, perform the assignment as part of the operator
- gen->write_binary_operator(target, assignment->variant_op, og_value, assigned_value);
- if (assigned_value.mode == GDScriptCodeGenerator::Address::TEMPORARY) {
- gen->pop_temporary(); // Pop assigned value if not done before.
- }
- return GDScriptCodeGenerator::Address();
- }
-
GDScriptCodeGenerator::Address op_result = codegen.add_temporary(_gdtype_from_datatype(assignment->get_datatype(), codegen.script));
+ GDScriptCodeGenerator::Address og_value = _parse_expression(codegen, r_error, assignment->assignee);
gen->write_binary_operator(op_result, assignment->variant_op, og_value, assigned_value);
to_assign = op_result;
diff --git a/modules/gdscript/tests/scripts/runtime/features/assign_operator.gd b/modules/gdscript/tests/scripts/runtime/features/assign_operator.gd
new file mode 100644
index 0000000000..2a9fe851ef
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/assign_operator.gd
@@ -0,0 +1,31 @@
+# https://github.com/godotengine/godot/issues/75832
+
+@warning_ignore("narrowing_conversion")
+func test():
+ var hf := 2.0
+ var sf = 2.0
+
+ var i := 2
+ i *= hf
+ i *= sf
+ i *= 2.0
+ print(i)
+ var v2 := Vector2i(1, 2)
+ v2 *= hf
+ v2 *= sf
+ v2 *= 2.0
+ print(v2)
+ var v3 := Vector3i(1, 2, 3)
+ v3 *= hf
+ v3 *= sf
+ v3 *= 2.0
+ print(v3)
+ var v4 := Vector4i(1, 2, 3, 4)
+ v4 *= hf
+ v4 *= sf
+ v4 *= 2.0
+ print(v4)
+
+ var arr := [1, 2, 3]
+ arr += [4, 5]
+ print(arr)
diff --git a/modules/gdscript/tests/scripts/runtime/features/assign_operator.out b/modules/gdscript/tests/scripts/runtime/features/assign_operator.out
new file mode 100644
index 0000000000..bfcfc1dff5
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/assign_operator.out
@@ -0,0 +1,6 @@
+GDTEST_OK
+16
+(8, 16)
+(8, 16, 24)
+(8, 16, 24, 32)
+[1, 2, 3, 4, 5]