From d3e4058aec30d9f23292dcf91408126977e29a59 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 28 Jan 2023 16:15:28 +0800 Subject: [PATCH] cgen: fix printing for mut v in arr (#17137) --- vlib/v/gen/c/str_intp.v | 3 +++ .../inout/printing_for_mut_v_in_a.out | 4 ++++ .../inout/printing_for_mut_v_in_a.vv | 21 +++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 vlib/v/slow_tests/inout/printing_for_mut_v_in_a.out create mode 100644 vlib/v/slow_tests/inout/printing_for_mut_v_in_a.vv diff --git a/vlib/v/gen/c/str_intp.v b/vlib/v/gen/c/str_intp.v index b8c3f967de..77415f3d8f 100644 --- a/vlib/v/gen/c/str_intp.v +++ b/vlib/v/gen/c/str_intp.v @@ -16,6 +16,9 @@ fn (mut g Gen) str_format(node ast.StringInterLiteral, i int) (u64, string) { mut base := 0 // numeric base mut upper_case := false // set upercase for the result string mut typ := g.unwrap_generic(node.expr_types[i]) + if node.exprs[i].is_auto_deref_var() { + typ = typ.deref() + } sym := g.table.sym(typ) if sym.kind == .alias { diff --git a/vlib/v/slow_tests/inout/printing_for_mut_v_in_a.out b/vlib/v/slow_tests/inout/printing_for_mut_v_in_a.out new file mode 100644 index 0000000000..fcf670bbc8 --- /dev/null +++ b/vlib/v/slow_tests/inout/printing_for_mut_v_in_a.out @@ -0,0 +1,4 @@ +mutable num is 255 +imutable element is 255 +mutable element is 255 +mutable element is 255 diff --git a/vlib/v/slow_tests/inout/printing_for_mut_v_in_a.vv b/vlib/v/slow_tests/inout/printing_for_mut_v_in_a.vv new file mode 100644 index 0000000000..3aca4149da --- /dev/null +++ b/vlib/v/slow_tests/inout/printing_for_mut_v_in_a.vv @@ -0,0 +1,21 @@ +fn main() { + // check to see if mutable integers work as expected + mut num := 255 + println('mutable num is ${num}') + + mut arr := [255] + // check to see if mutable arrays with immutable iteration work as expected + for elem in arr { + println('imutable element is ${elem}') + } + + // check to see if mutable arrays with mutable iteration work as expected + for mut elem in arr { + println('mutable element is ${elem}') + } + + // check to see if mutable arrays with mutable iteration work as expected (explicit format) + for mut elem in arr { + println('mutable element is ${elem:d}') + } +}