From 6e35748b7cfc5dc0bfba047bda1737cbc74b7e18 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 12 Sep 2026 11:40:45 +0200 Subject: [PATCH] Fixed incorrect operand equality check --- src/ssa/BinaryOp.go | 4 ++-- src/ssa/UnaryOp.go | 2 +- tests/loop-nested-modify.q | 14 ++++++++++++++ tests/tests_test.go | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 tests/loop-nested-modify.q diff --git a/src/ssa/BinaryOp.go b/src/ssa/BinaryOp.go index 516ae13..f913d73 100644 --- a/src/ssa/BinaryOp.go +++ b/src/ssa/BinaryOp.go @@ -29,11 +29,11 @@ func (a *BinaryOp) Equals(v Value) bool { return false } - if a.Left.Equals(b.Left) && a.Right.Equals(b.Right) { + if a.Left == b.Left && a.Right == b.Right { return true } - return a.Op.IsCommutative() && a.Left.Equals(b.Right) && a.Right.Equals(b.Left) + return a.Op.IsCommutative() && a.Left == b.Right && a.Right == b.Left } // Inputs returns the left and right operands. diff --git a/src/ssa/UnaryOp.go b/src/ssa/UnaryOp.go index 903a71c..cc980b2 100644 --- a/src/ssa/UnaryOp.go +++ b/src/ssa/UnaryOp.go @@ -27,7 +27,7 @@ func (a *UnaryOp) Equals(v Value) bool { return false } - return a.Operand.Equals(b.Operand) + return a.Operand == b.Operand } // Inputs returns the operand. diff --git a/tests/loop-nested-modify.q b/tests/loop-nested-modify.q new file mode 100644 index 0000000..c5be358 --- /dev/null +++ b/tests/loop-nested-modify.q @@ -0,0 +1,14 @@ +main() { + count := 0 + + loop i := 2..11 { + loop j := 2..3 { + j += 2 + i += 2 + } + + count += 1 + } + + assert count == 3 +} \ No newline at end of file diff --git a/tests/tests_test.go b/tests/tests_test.go index be7021e..e881eb5 100644 --- a/tests/tests_test.go +++ b/tests/tests_test.go @@ -93,6 +93,7 @@ var tests = []run{ {"loop-nested-xy", nil, "", "0,0\n0,1\n0,2\n1,0\n1,1\n1,2\n2,0\n2,1\n2,2\n", 0}, {"loop-nested-xyz", nil, "", "0,0,0\n0,0,1\n0,0,2\n0,1,0\n0,1,1\n0,1,2\n0,2,0\n0,2,1\n0,2,2\n1,0,0\n1,0,1\n1,0,2\n1,1,0\n1,1,1\n1,1,2\n1,2,0\n1,2,1\n1,2,2\n2,0,0\n2,0,1\n2,0,2\n2,1,0\n2,1,1\n2,1,2\n2,2,0\n2,2,1\n2,2,2\n", 0}, {"loop-nested-return", nil, "", "..........", 0}, + {"loop-nested-modify", nil, "", "", 0}, {"commutativity", nil, "", "", 0}, {"factorial", nil, "", "", 0}, {"fibonacci", nil, "", "", 0}, -- 2.51.2