Skip to content

Commit 0800feb

Browse files
authored
cgen: fix shared int string intp (fix #25984) (#25989)
1 parent f8b74d7 commit 0800feb

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

vlib/v/gen/c/str_intp.v

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ fn (mut g Gen) str_format(node ast.StringInterLiteral, i int, fmts []u8) (u64, s
5454
typ = typ.deref()
5555
}
5656
typ = g.table.final_type(typ)
57+
if typ.has_flag(.shared_f) {
58+
typ = typ.clear_flag(.shared_f).deref()
59+
}
5760
mut remove_tail_zeros := false
5861
fspec := fmts[i]
5962
mut fmt_type := StrIntpType.si_no_str
@@ -270,18 +273,27 @@ fn (mut g Gen) str_val(node ast.StringInterLiteral, i int, fmts []u8) {
270273
g.write('*')
271274
}
272275
g.expr(expr)
276+
if typ.has_flag(.shared_f) {
277+
g.write('->val')
278+
}
273279
g.write(')')
274280
} else {
275281
if expr.is_auto_deref_var() && fmt != `p` {
276282
g.write('*')
277283
}
278284
g.expr(expr)
285+
if typ.has_flag(.shared_f) {
286+
g.write('->val')
287+
}
279288
}
280289
} else {
281290
if expr.is_auto_deref_var() && fmt != `p` {
282291
g.write('*')
283292
}
284293
g.expr(expr)
294+
if typ.has_flag(.shared_f) {
295+
g.write('->val')
296+
}
285297
}
286298
}
287299

vlib/v/tests/shared_str_inp_test.v

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module main
2+
3+
struct Foo {
4+
mut:
5+
int shared int
6+
i32 shared i32
7+
i64 shared i64
8+
u32 shared u32
9+
u64 shared u64
10+
}
11+
12+
fn test_main() {
13+
mut t := Foo{}
14+
rlock t.int {
15+
assert '${t.int}' == '0'
16+
}
17+
18+
rlock t.i32 {
19+
assert '${t.i32}' == '0'
20+
}
21+
rlock t.i64 {
22+
assert '${t.i64}' == '0'
23+
}
24+
rlock t.u32 {
25+
assert '${t.u32}' == '0'
26+
}
27+
rlock t.u64 {
28+
assert '${t.u64}' == '0'
29+
}
30+
31+
rlock t.i32 {
32+
assert '${t.i32:08x}' == '00000000'
33+
}
34+
}

0 commit comments

Comments
 (0)