v2 / vlib / v / tests / fns / generic_closure_assignment_test.v
23 lines · 20 sloc · 371 bytes · 3fc4d7efd98df4698243d88d5426c6a53a834dd3
Raw
1struct Test[T] {
2mut:
3 val T
4}
5
6fn (mut t Test[T]) set_val(val T) {
7 t.val = val
8}
9
10fn process[T](mut t Test[T]) int {
11 t.set_val('qqq')
12 anon := fn [t] [T]() int {
13 println(t)
14 return 1
15 }
16 return anon()
17}
18
19fn test_generic_closure_with_generic_capture_can_be_assigned_to_local_variable() {
20 mut t := Test[string]{}
21 assert process(mut t) == 1
22 assert t.val == 'qqq'
23}
24