From 0800feb35aec2eed8a730858d429dbd9f93a914e Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Wed, 17 Dec 2025 18:14:16 +0800 Subject: [PATCH] cgen: fix shared int string intp (fix #25984) (#25989) --- vlib/v/gen/c/str_intp.v | 12 +++++++++++ vlib/v/tests/shared_str_inp_test.v | 34 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 vlib/v/tests/shared_str_inp_test.v diff --git a/vlib/v/gen/c/str_intp.v b/vlib/v/gen/c/str_intp.v index 09335f8f3..a1045195c 100644 --- a/vlib/v/gen/c/str_intp.v +++ b/vlib/v/gen/c/str_intp.v @@ -54,6 +54,9 @@ fn (mut g Gen) str_format(node ast.StringInterLiteral, i int, fmts []u8) (u64, s typ = typ.deref() } typ = g.table.final_type(typ) + if typ.has_flag(.shared_f) { + typ = typ.clear_flag(.shared_f).deref() + } mut remove_tail_zeros := false fspec := fmts[i] mut fmt_type := StrIntpType.si_no_str @@ -270,18 +273,27 @@ fn (mut g Gen) str_val(node ast.StringInterLiteral, i int, fmts []u8) { g.write('*') } g.expr(expr) + if typ.has_flag(.shared_f) { + g.write('->val') + } g.write(')') } else { if expr.is_auto_deref_var() && fmt != `p` { g.write('*') } g.expr(expr) + if typ.has_flag(.shared_f) { + g.write('->val') + } } } else { if expr.is_auto_deref_var() && fmt != `p` { g.write('*') } g.expr(expr) + if typ.has_flag(.shared_f) { + g.write('->val') + } } } diff --git a/vlib/v/tests/shared_str_inp_test.v b/vlib/v/tests/shared_str_inp_test.v new file mode 100644 index 000000000..eb54b481a --- /dev/null +++ b/vlib/v/tests/shared_str_inp_test.v @@ -0,0 +1,34 @@ +module main + +struct Foo { +mut: + int shared int + i32 shared i32 + i64 shared i64 + u32 shared u32 + u64 shared u64 +} + +fn test_main() { + mut t := Foo{} + rlock t.int { + assert '${t.int}' == '0' + } + + rlock t.i32 { + assert '${t.i32}' == '0' + } + rlock t.i64 { + assert '${t.i64}' == '0' + } + rlock t.u32 { + assert '${t.u32}' == '0' + } + rlock t.u64 { + assert '${t.u64}' == '0' + } + + rlock t.i32 { + assert '${t.i32:08x}' == '00000000' + } +} -- 2.39.5