v2 / vlib / v / gen / c / testdata / if_guard_heap_object.vv
24 lines · 22 sloc · 292 bytes · ff88f1648daf2b7f1b4d27fda6277b394658bdef
Raw
1@[heap]
2struct HeapImage {
3mut:
4 id int
5}
6
7fn create_image() ?HeapImage {
8 return HeapImage{
9 id: 42
10 }
11}
12
13fn main() {
14 if img := create_image() {
15 println(img.id)
16 }
17 image := HeapImage{
18 id: 7
19 }
20 mut images := []HeapImage{}
21 images << image
22 indexed := images[0]
23 println(indexed.id)
24}
25