Skip to content

Commit

Permalink
cgen: fix for in mut array with infix expr (#17233)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Feb 6, 2023
1 parent 954843c commit 223c752
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
28 changes: 12 additions & 16 deletions vlib/v/gen/c/infix.v
Expand Up @@ -144,12 +144,12 @@ fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) {
}
g.write('${ptr_typ}_alias_eq(')
if left.typ.is_ptr() {
g.write('*')
g.write('*'.repeat(left.typ.nr_muls()))
}
g.expr(node.left)
g.write(', ')
if right.typ.is_ptr() {
g.write('*')
g.write('*'.repeat(right.typ.nr_muls()))
}
g.expr(node.right)
g.write(')')
Expand All @@ -161,15 +161,15 @@ fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) {
}
g.write('${ptr_typ}_arr_eq(')
if left.typ.is_ptr() && !left.typ.has_flag(.shared_f) {
g.write('*')
g.write('*'.repeat(left.typ.nr_muls()))
}
g.expr(node.left)
if left.typ.has_flag(.shared_f) {
g.write('->val')
}
g.write(', ')
if right.typ.is_ptr() && !right.typ.has_flag(.shared_f) {
g.write('*')
g.write('*'.repeat(right.typ.nr_muls()))
}
g.expr(node.right)
if right.typ.has_flag(.shared_f) {
Expand Down Expand Up @@ -210,36 +210,32 @@ fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) {
}
g.write('${ptr_typ}_map_eq(')
if left.typ.is_ptr() {
g.write('*')
g.write('*'.repeat(left.typ.nr_muls()))
}
g.expr(node.left)
g.write(', ')
if right.typ.is_ptr() {
g.write('*')
g.write('*'.repeat(right.typ.nr_muls()))
}
g.expr(node.right)
g.write(')')
}
.struct_ {
// if g.pref.translated {
// g.gen_plain_infix_expr(node)
//} else {
ptr_typ := g.equality_fn(left.unaliased)
if node.op == .ne {
g.write('!')
}
g.write('${ptr_typ}_struct_eq(')
if left.typ.is_ptr() {
g.write('*')
g.write('*'.repeat(left.typ.nr_muls()))
}
g.expr(node.left)
g.write(', ')
if right.typ.is_ptr() {
g.write('*')
g.write('*'.repeat(right.typ.nr_muls()))
}
g.expr(node.right)
g.write(')')
//}
}
.sum_type {
ptr_typ := g.equality_fn(left.unaliased)
Expand All @@ -248,12 +244,12 @@ fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) {
}
g.write('${ptr_typ}_sumtype_eq(')
if left.typ.is_ptr() {
g.write('*')
g.write('*'.repeat(left.typ.nr_muls()))
}
g.expr(node.left)
g.write(', ')
if right.typ.is_ptr() {
g.write('*')
g.write('*'.repeat(right.typ.nr_muls()))
}
g.expr(node.right)
g.write(')')
Expand All @@ -265,12 +261,12 @@ fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) {
}
g.write('${ptr_typ}_interface_eq(')
if left.typ.is_ptr() {
g.write('*')
g.write('*'.repeat(left.typ.nr_muls()))
}
g.expr(node.left)
g.write(', ')
if right.typ.is_ptr() {
g.write('*')
g.write('*'.repeat(right.typ.nr_muls()))
}
g.expr(node.right)
g.write(')')
Expand Down
13 changes: 13 additions & 0 deletions vlib/v/tests/for_in_mut_array_with_infix_expr_test.v
@@ -0,0 +1,13 @@
import net

fn test_for_in_mut_array_with_infix_expr() {
ignore := net.TcpConn{}
mut array := []&net.TcpConn{}

for mut socket in array {
if ignore != socket {
println('not eq')
}
}
assert true
}

0 comments on commit 223c752

Please sign in to comment.