v2 / vlib / v / gen / c / testdata / defer_fn_match_branch_capture.vv
31 lines · 27 sloc · 399 bytes · dff5b1e58122fd131c5ec38b27d095741559a9a6
Raw
1// vtest vflags: -cstrict -cc clang
2
3struct Object {
4mut:
5 context bool
6}
7
8fn (mut o Object) f(x int) int {
9 match x {
10 0 {
11 old := o.context
12 defer(fn) {
13 o.context = old
14 }
15 o.context = true
16 }
17 1 {
18 return 123
19 }
20 else {}
21 }
22
23 return 42
24}
25
26fn main() {
27 mut o := Object{}
28 println('${o.f(0)} ${o.context}')
29 println('${o.f(1)} ${o.context}')
30 println('${o.f(2)} ${o.context}')
31}
32