From ae592299dc70dbb4ecbb8c73ef04f76a74885cec Mon Sep 17 00:00:00 2001 From: yuyi Date: Wed, 13 Jan 2021 15:32:41 +0800 Subject: [PATCH] cgen: fix fixed arrays literal eq (#8079) --- vlib/builtin/array_eq_test.v | 14 ++++++++++++++ vlib/v/gen/cgen.v | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/vlib/builtin/array_eq_test.v b/vlib/builtin/array_eq_test.v index 71d369f945..280f58069d 100644 --- a/vlib/builtin/array_eq_test.v +++ b/vlib/builtin/array_eq_test.v @@ -44,3 +44,17 @@ fn test_fixed_array_eq() { assert a8 == [['aaa', 'bbb']!!, ['ccc', 'ddd']!!] assert a8 != [['bbb', 'aaa']!!, ['cccc', 'dddd']!!] } + +fn test_fixed_array_literal_eq() { + assert [1, 2, 3]! == [1, 2, 3]! + assert [1, 1, 1]! != [1, 2, 3]! + + assert [[1, 2], [3, 4]]! == [[1, 2], [3, 4]]! + assert [[1, 1], [2, 2]]! != [[1, 2], [3, 4]]! + + assert [[1, 1]!, [2, 2]!]! == [[1, 1]!, [2, 2]!]! + assert [[1, 1]!, [2, 2]!]! != [[1, 2]!, [2, 3]!]! + + assert [[1, 1]!, [2, 2]!] == [[1, 1]!, [2, 2]!] + assert [[1, 1]!, [2, 2]!] != [[1, 2]!, [2, 3]!] +} diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 58034b8c85..987ca3fe90 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -3032,6 +3032,10 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) { if node.left_type.is_ptr() { g.write('*') } + if node.left is ast.ArrayInit { + s := g.typ(left_type) + g.write('($s)') + } g.expr(node.left) g.write(', ') if node.right is ast.ArrayInit {