v2 / vlib / v / gen / c / testdata / heap_struct_init_result_propagation.vv
39 lines · 34 sloc · 550 bytes · ed9a01dda4d67f463d248a8f30d19ef3f3f54ac9
Raw
1// vtest vflags: -prod
2import os
3
4struct Process {
5 path string
6 argv []string
7 dir string
8}
9
10struct Command {
11 path string
12 args []string
13 dir string
14mut:
15 process &Process = unsafe { nil }
16}
17
18fn lookup(cmd string) !string {
19 return os.find_abs_path_of_executable(cmd)!
20}
21
22fn build(mut c Command) ! {
23 if !isnil(c.process) {
24 return error('reuse')
25 }
26 c.process = &Process{
27 path: lookup(c.path)!
28 argv: c.args
29 dir: c.dir
30 }
31}
32
33fn main() {
34 mut cmd := Command{
35 path: 'bash'
36 args: ['-c', 'echo ok']
37 }
38 build(mut cmd) or { panic(err) }
39}
40