Skip to content

Commit 3688abb

Browse files
committed
c error while compiling using with the v ui libr... (fixes #18952)
1 parent e71d04b commit 3688abb

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

vlib/v/gen/c/fn.v

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,20 +2392,14 @@ fn (mut g Gen) autofree_call_pregen(node ast.CallExpr) {
23922392
s = 'string ${t} = '
23932393
}
23942394
g.is_autofree_tmp = true
2395-
pos_before := g.out.len
2396-
23972395
old_is_autofree := g.is_autofree
23982396
if arg.expr is ast.CallExpr && arg.expr.is_method && arg.expr.left is ast.CallExpr {
23992397
g.is_autofree = false
24002398
}
24012399

2402-
g.expr(arg.expr)
2403-
expr_code := g.out.cut_to(pos_before).trim_space()
2404-
2400+
s = g.expr_string_surround(s, arg.expr, ';').trim_space()
24052401
g.is_autofree = old_is_autofree
24062402
g.is_autofree_tmp = false
2407-
s += expr_code
2408-
s += ';'
24092403
g.strs_to_free0 << s
24102404
// This tmp arg var will be freed with the rest of the vars at the end of the scope.
24112405
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// vtest vflags: -autofree
2+
module main
3+
4+
const no_style = 'no_style'
5+
const no_string = ''
6+
7+
struct TextStyleParams {
8+
id string = no_style
9+
font_name string = no_string
10+
color string
11+
size int = -1
12+
align int
13+
vertical_align int
14+
}
15+
16+
fn draw_text(text string, ts TextStyleParams) string {
17+
return text + ts.color
18+
}
19+
20+
fn test_autofree_if_expr_call_arg_with_struct_init() {
21+
files_dropped := true
22+
got := draw_text(if files_dropped {
23+
'Empty listbox. Drop files here ...'
24+
} else {
25+
''
26+
}, color: 'gray')
27+
assert got == 'Empty listbox. Drop files here ...gray'
28+
}

0 commit comments

Comments
 (0)