Skip to content

Commit

Permalink
cgen: fix dumping array of reference (vlang#21694)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 authored Jun 18, 2024
1 parent 488fd4f commit de5ad8b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions vlib/v/gen/c/dumpexpr.v
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn (mut g Gen) dump_expr(node ast.DumpExpr) {
name = name[3..]
}
dump_fn_name := '_v_dump_expr_${name}' +
(if expr_type.is_ptr() { '_ptr'.repeat(expr_type.nr_muls()) } else { '' })
(if expr_type.is_ptr() { '__ptr'.repeat(expr_type.nr_muls()) } else { '' })
g.write(' ${dump_fn_name}(${ctoslit(fpath)}, ${line}, ${sexpr}, ')
if expr_type.has_flag(.shared_f) {
g.write('&')
Expand Down Expand Up @@ -156,7 +156,7 @@ fn (mut g Gen) dump_expr_definitions() {
str_dumparg_ret_type = str_dumparg_type
}
dump_fn_name := '_v_dump_expr_${name}' +
(if is_ptr { '_ptr'.repeat(typ.nr_muls()) } else { '' })
(if is_ptr { '__ptr'.repeat(typ.nr_muls()) } else { '' })

// protect against duplicate declarations:
if dump_already_generated_fns[dump_fn_name] {
Expand Down
10 changes: 10 additions & 0 deletions vlib/v/slow_tests/inout/dump_array_of_ref.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[vlib/v/slow_tests/inout/dump_array_of_ref.vv:6] parents: &[Balise{
a: 11
}, Balise{
a: 22
}]
[vlib/v/slow_tests/inout/dump_array_of_ref.vv:10] stack: [&Balise{
a: 10
}, &Balise{
a: 20
}]
16 changes: 16 additions & 0 deletions vlib/v/slow_tests/inout/dump_array_of_ref.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
struct Balise {
a int
}

fn escape_tag(mut parents []Balise) {
dump(parents)
mut stack := []&Balise{}
stack << &Balise{10}
stack << &Balise{20}
dump(stack)
}

fn main() {
mut bal := [Balise{11}, Balise{22}]
escape_tag(mut bal)
}

0 comments on commit de5ad8b

Please sign in to comment.