vxx2 / vlib / v / checker / tests / struct_field_map_address_err.vv
27 lines · 24 sloc · 551 bytes · 0c8ce3bcb9fd4a2e5bd5f991a5a07da976d780d7
Raw
1import os
2
3struct StructWithMap {
4mut:
5 name string
6 m map[string]StructWithMap
7}
8
9fn abc() (&StructWithMap, &map[string]StructWithMap) {
10 mut s := &StructWithMap{}
11 s.m['abc'] = StructWithMap{'abc', {}}
12 pointer_to_map_value := &s.m['abc'].m['xyz'].m
13 dump(ptr_str(pointer_to_map_value))
14 return s, pointer_to_map_value
15}
16
17fn main() {
18 mut s, p := abc()
19 n := os.args[1] or { '2' }.int()
20 dump(n)
21 for i in 0 .. n {
22 s.m['${i}'] = StructWithMap{}
23 }
24 dump(s.m['abc'])
25 dump(p)
26 eprintln('-----------------------------------------------------')
27}
28