From de5ad8b11872ef4ccc83274261ceffdd8c3f4de5 Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 18 Jun 2024 18:06:20 +0800 Subject: [PATCH] cgen: fix dumping array of reference (#21694) --- vlib/v/gen/c/dumpexpr.v | 4 ++-- vlib/v/slow_tests/inout/dump_array_of_ref.out | 10 ++++++++++ vlib/v/slow_tests/inout/dump_array_of_ref.vv | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 vlib/v/slow_tests/inout/dump_array_of_ref.out create mode 100644 vlib/v/slow_tests/inout/dump_array_of_ref.vv diff --git a/vlib/v/gen/c/dumpexpr.v b/vlib/v/gen/c/dumpexpr.v index f46a679b6..f18af6672 100644 --- a/vlib/v/gen/c/dumpexpr.v +++ b/vlib/v/gen/c/dumpexpr.v @@ -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('&') @@ -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] { diff --git a/vlib/v/slow_tests/inout/dump_array_of_ref.out b/vlib/v/slow_tests/inout/dump_array_of_ref.out new file mode 100644 index 000000000..cfec8e262 --- /dev/null +++ b/vlib/v/slow_tests/inout/dump_array_of_ref.out @@ -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 +}] diff --git a/vlib/v/slow_tests/inout/dump_array_of_ref.vv b/vlib/v/slow_tests/inout/dump_array_of_ref.vv new file mode 100644 index 000000000..986558a09 --- /dev/null +++ b/vlib/v/slow_tests/inout/dump_array_of_ref.vv @@ -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) +} -- 2.39.5