cgen: fix == for mut arraay args (#5648)
parent
da98c3c135
commit
765ffa37eb
|
@ -877,3 +877,24 @@ fn test_plus_assign_string() {
|
||||||
a[0] += 'abc'
|
a[0] += 'abc'
|
||||||
assert a == ['abc']
|
assert a == ['abc']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn mut_arr_with_eq_in_fn(mut a []int) {
|
||||||
|
if a == [1,2,3,4] {
|
||||||
|
a[0] = 0
|
||||||
|
}
|
||||||
|
if [0,2,3,4] == a {
|
||||||
|
a[1] = 0
|
||||||
|
}
|
||||||
|
if !(a != [0,0,3,4]) {
|
||||||
|
a[2] = 0
|
||||||
|
}
|
||||||
|
if !([0,0,0,4] != a) {
|
||||||
|
a[3] = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_mut_arr_with_eq_in_fn() {
|
||||||
|
mut a := [1,2,3,4]
|
||||||
|
mut_arr_with_eq_in_fn(mut a)
|
||||||
|
assert a == [0,0,0,0]
|
||||||
|
}
|
||||||
|
|
|
@ -1879,8 +1879,14 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) {
|
||||||
} else if node.op == .ne {
|
} else if node.op == .ne {
|
||||||
g.write('!${ptr_typ}_arr_eq(')
|
g.write('!${ptr_typ}_arr_eq(')
|
||||||
}
|
}
|
||||||
|
if node.left_type.is_ptr() {
|
||||||
|
g.write('*')
|
||||||
|
}
|
||||||
g.expr(node.left)
|
g.expr(node.left)
|
||||||
g.write(', ')
|
g.write(', ')
|
||||||
|
if node.right_type.is_ptr() {
|
||||||
|
g.write('*')
|
||||||
|
}
|
||||||
g.expr(node.right)
|
g.expr(node.right)
|
||||||
g.write(')')
|
g.write(')')
|
||||||
} else if node.op in [.key_in, .not_in] {
|
} else if node.op in [.key_in, .not_in] {
|
||||||
|
@ -2814,7 +2820,7 @@ fn (mut g Gen) assoc(node ast.Assoc) {
|
||||||
fn (mut g Gen) gen_array_equality_fn(left table.Type) string {
|
fn (mut g Gen) gen_array_equality_fn(left table.Type) string {
|
||||||
left_sym := g.table.get_type_symbol(left)
|
left_sym := g.table.get_type_symbol(left)
|
||||||
typ_name := g.typ(left)
|
typ_name := g.typ(left)
|
||||||
ptr_typ := typ_name[typ_name.index_after('_', 0) + 1..]
|
ptr_typ := typ_name[typ_name.index_after('_', 0) + 1..].trim('*')
|
||||||
elem_sym := g.table.get_type_symbol(left_sym.array_info().elem_type)
|
elem_sym := g.table.get_type_symbol(left_sym.array_info().elem_type)
|
||||||
elem_typ := g.typ(left_sym.array_info().elem_type)
|
elem_typ := g.typ(left_sym.array_info().elem_type)
|
||||||
ptr_elem_typ := elem_typ[elem_typ.index_after('_', 0) + 1..]
|
ptr_elem_typ := elem_typ[elem_typ.index_after('_', 0) + 1..]
|
||||||
|
|
Loading…
Reference in New Issue