v2 / vlib / v / tests / options / option_free_method_test.v
38 lines · 32 sloc · 333 bytes · 2ad83399239548c11fb3f61c2b6309f7d101f6f5
Raw
1pub struct Test2 {
2 a int
3}
4
5pub struct Test {
6 a Test2
7 b ?string
8 c ?Test2
9 d ?&Test2
10}
11
12@[manualfree]
13fn test_main() {
14 t := Test{
15 b: 'b'
16 }
17
18 println('t: ${t}')
19
20 defer {
21 unsafe {
22 t.free()
23 }
24 }
25
26 mut t2 := ?Test(Test{
27 b: 'b'
28 })
29 println('t: ${t2}')
30
31 defer {
32 unsafe {
33 if t2 != none {
34 t2.free()
35 }
36 }
37 }
38}
39