v2 / vlib / v / tests / structs / struct_field_shared_test.v
26 lines · 25 sloc · 317 bytes · 8f0242e6af5e524ac96eb4b80f34d0b69e599068
Raw
1struct Foo {
2 bar shared struct {
3 mut:
4 foo int
5 bar int
6 }
7 baz shared int
8}
9
10fn test_main() {
11 assert Foo{}.str() == 'Foo{
12 bar: struct {
13 foo: 0
14 bar: 0
15 }
16 baz: 0
17}'
18 mut t := Foo{}
19 lock t.bar {
20 t.bar.foo = 1
21 t.bar.bar = 2
22 }
23 rlock t.bar {
24 assert t.bar.foo + t.bar.bar == 3
25 }
26}
27