cgen: fix fixed arrays literal eq (#8079)

pull/8082/head
yuyi 2021-01-13 15:32:41 +08:00 committed by GitHub
parent 7458b699d0
commit ae592299dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -44,3 +44,17 @@ fn test_fixed_array_eq() {
assert a8 == [['aaa', 'bbb']!!, ['ccc', 'ddd']!!] assert a8 == [['aaa', 'bbb']!!, ['ccc', 'ddd']!!]
assert a8 != [['bbb', 'aaa']!!, ['cccc', 'dddd']!!] 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]!]
}

View File

@ -3032,6 +3032,10 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) {
if node.left_type.is_ptr() { if node.left_type.is_ptr() {
g.write('*') g.write('*')
} }
if node.left is ast.ArrayInit {
s := g.typ(left_type)
g.write('($s)')
}
g.expr(node.left) g.expr(node.left)
g.write(', ') g.write(', ')
if node.right is ast.ArrayInit { if node.right is ast.ArrayInit {