Skip to content

Commit e3caae9

Browse files
authored
cgen: fix struct init with multi option fn type (#19491)
1 parent 7ebee2e commit e3caae9

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

vlib/v/gen/c/cgen.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,6 +1981,7 @@ fn (mut g Gen) expr_with_tmp_var(expr ast.Expr, expr_typ ast.Type, ret_typ ast.T
19811981
} else {
19821982
g.writeln(' }, (${c.result_name}*)(&${tmp_var}), sizeof(${styp}));')
19831983
}
1984+
g.set_current_pos_as_last_stmt_pos()
19841985
}
19851986

19861987
g.write(stmt_str)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// CycleMenuItem is a menu item that can be cycled through by pressing a button.
2+
pub struct CycleMenuItem {
3+
mut:
4+
label string
5+
values []string
6+
on CycleMenuItemEvents
7+
}
8+
9+
// CycleMenuItemEvents is a set of events that can be invoked by a
10+
// `CycleMenuItem`.
11+
[params]
12+
pub struct CycleMenuItemEvents {
13+
__global:
14+
click ?fn (string) bool
15+
cycle ?fn (string) bool
16+
}
17+
18+
// CycleMenuItem.new creates a new `CycleMenuItem` with the given label, values,
19+
// and function to invoke when the item is selected.
20+
[inline]
21+
pub fn CycleMenuItem.new(label string, values []string, events CycleMenuItemEvents) CycleMenuItem {
22+
return CycleMenuItem{
23+
label: label
24+
values: values
25+
on: events
26+
}
27+
}
28+
29+
fn test_struct_init_with_multi_option_fn_type() {
30+
item := CycleMenuItem.new('FPS', ['30', '60', '90', '120', '144', '165', 'unlimited'],
31+
click: fn (value string) bool {
32+
if value == 'unlimited' {
33+
return true
34+
} else {
35+
return false
36+
}
37+
}
38+
)
39+
func := item.on.click?
40+
ret := func('unlimited')
41+
println(ret)
42+
assert ret
43+
}

0 commit comments

Comments
 (0)