Skip to content

Commit

Permalink
cgen: fix infix array heap comparison (#21145)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Mar 30, 2024
1 parent a63a733 commit 360886b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions vlib/v/gen/c/infix.v
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,19 @@ 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('*'.repeat(left.typ.nr_muls()))
if node.left !is ast.ArrayInit {
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('*'.repeat(right.typ.nr_muls()))
if node.right !is ast.ArrayInit {
g.write('*'.repeat(right.typ.nr_muls()))
}
}
g.expr(node.right)
if right.typ.has_flag(.shared_f) {
Expand Down
24 changes: 24 additions & 0 deletions vlib/v/tests/array_ptr_compare_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@[heap]
struct Particle {
}

@[heap]
struct App {
mut:
list_opti [][]&Particle
}

fn (mut app App) init_opti_list() {
for mut liste in app.list_opti {
if liste != [] {
liste.clear()
}
}
}

fn test_main() {
mut app := &App{
list_opti: [][]&Particle{len: 10, init: []&Particle{}}
}
app.init_opti_list()
}

0 comments on commit 360886b

Please sign in to comment.