Skip to content

Commit 223c752

Browse files
authored
cgen: fix for in mut array with infix expr (#17233)
1 parent 954843c commit 223c752

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

vlib/v/gen/c/infix.v

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) {
144144
}
145145
g.write('${ptr_typ}_alias_eq(')
146146
if left.typ.is_ptr() {
147-
g.write('*')
147+
g.write('*'.repeat(left.typ.nr_muls()))
148148
}
149149
g.expr(node.left)
150150
g.write(', ')
151151
if right.typ.is_ptr() {
152-
g.write('*')
152+
g.write('*'.repeat(right.typ.nr_muls()))
153153
}
154154
g.expr(node.right)
155155
g.write(')')
@@ -161,15 +161,15 @@ fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) {
161161
}
162162
g.write('${ptr_typ}_arr_eq(')
163163
if left.typ.is_ptr() && !left.typ.has_flag(.shared_f) {
164-
g.write('*')
164+
g.write('*'.repeat(left.typ.nr_muls()))
165165
}
166166
g.expr(node.left)
167167
if left.typ.has_flag(.shared_f) {
168168
g.write('->val')
169169
}
170170
g.write(', ')
171171
if right.typ.is_ptr() && !right.typ.has_flag(.shared_f) {
172-
g.write('*')
172+
g.write('*'.repeat(right.typ.nr_muls()))
173173
}
174174
g.expr(node.right)
175175
if right.typ.has_flag(.shared_f) {
@@ -210,36 +210,32 @@ fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) {
210210
}
211211
g.write('${ptr_typ}_map_eq(')
212212
if left.typ.is_ptr() {
213-
g.write('*')
213+
g.write('*'.repeat(left.typ.nr_muls()))
214214
}
215215
g.expr(node.left)
216216
g.write(', ')
217217
if right.typ.is_ptr() {
218-
g.write('*')
218+
g.write('*'.repeat(right.typ.nr_muls()))
219219
}
220220
g.expr(node.right)
221221
g.write(')')
222222
}
223223
.struct_ {
224-
// if g.pref.translated {
225-
// g.gen_plain_infix_expr(node)
226-
//} else {
227224
ptr_typ := g.equality_fn(left.unaliased)
228225
if node.op == .ne {
229226
g.write('!')
230227
}
231228
g.write('${ptr_typ}_struct_eq(')
232229
if left.typ.is_ptr() {
233-
g.write('*')
230+
g.write('*'.repeat(left.typ.nr_muls()))
234231
}
235232
g.expr(node.left)
236233
g.write(', ')
237234
if right.typ.is_ptr() {
238-
g.write('*')
235+
g.write('*'.repeat(right.typ.nr_muls()))
239236
}
240237
g.expr(node.right)
241238
g.write(')')
242-
//}
243239
}
244240
.sum_type {
245241
ptr_typ := g.equality_fn(left.unaliased)
@@ -248,12 +244,12 @@ fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) {
248244
}
249245
g.write('${ptr_typ}_sumtype_eq(')
250246
if left.typ.is_ptr() {
251-
g.write('*')
247+
g.write('*'.repeat(left.typ.nr_muls()))
252248
}
253249
g.expr(node.left)
254250
g.write(', ')
255251
if right.typ.is_ptr() {
256-
g.write('*')
252+
g.write('*'.repeat(right.typ.nr_muls()))
257253
}
258254
g.expr(node.right)
259255
g.write(')')
@@ -265,12 +261,12 @@ fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) {
265261
}
266262
g.write('${ptr_typ}_interface_eq(')
267263
if left.typ.is_ptr() {
268-
g.write('*')
264+
g.write('*'.repeat(left.typ.nr_muls()))
269265
}
270266
g.expr(node.left)
271267
g.write(', ')
272268
if right.typ.is_ptr() {
273-
g.write('*')
269+
g.write('*'.repeat(right.typ.nr_muls()))
274270
}
275271
g.expr(node.right)
276272
g.write(')')
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import net
2+
3+
fn test_for_in_mut_array_with_infix_expr() {
4+
ignore := net.TcpConn{}
5+
mut array := []&net.TcpConn{}
6+
7+
for mut socket in array {
8+
if ignore != socket {
9+
println('not eq')
10+
}
11+
}
12+
assert true
13+
}

0 commit comments

Comments
 (0)