1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix for in mut array with infix expr (#17233)

This commit is contained in:
yuyi 2023-02-07 06:10:07 +08:00 committed by GitHub
parent 954843c486
commit 223c752460
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 16 deletions

View File

@ -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(')')
@ -161,7 +161,7 @@ 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) {
@ -169,7 +169,7 @@ fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) {
}
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) {
@ -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)
@ -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(')')
@ -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(')')

View File

@ -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
}