v2 / vlib / v / tests / concurrency / shared_generic_test.v
25 lines · 22 sloc · 397 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Foo[T] {
2 a T
3}
4
5fn test_shared_struct_has_generics() {
6 shared foo := Foo[int]{1}
7 lock foo {
8 assert foo.a == 1
9 }
10 shared bar := &Foo[int]{1}
11 lock bar {
12 assert bar.a == 1
13 }
14}
15
16fn generic_struct_as_parameters(shared arg Foo[int]) {
17 rlock arg {
18 assert arg.a == 1
19 }
20}
21
22fn test_generic_struct_as_parameters() {
23 shared foo := Foo[int]{1}
24 generic_struct_as_parameters(shared foo)
25}
26