v2 / vlib / v / parser / tests / defer_propagate2.vv
23 lines · 20 sloc · 258 bytes · 2332ecff4811b8c97dfda8e825170e9397962519
Raw
1struct Abc {
2mut:
3 x int = 123
4}
5
6fn (mut s Abc) close() ? {
7 println('> CLOSE 1 s.x: ${s.x}')
8 s.x = -1
9 println('> CLOSE 2 s.x: ${s.x}')
10}
11
12fn opt2() ?int {
13 mut s := Abc{}
14 dump(s.x)
15 defer {
16 s.close()?
17 }
18 return s.x
19}
20
21fn main() {
22 println(opt2()?)
23}
24