v2 / vlib / v / tests / generics / generics_indirect_test.v
32 lines · 27 sloc · 554 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1const zzz = &Local{}
2
3struct Local {
4 aborted bool
5}
6
7pub fn current() &Local {
8 return zzz
9}
10
11pub fn store[T](var &T, value T) {
12 eprintln('store ${voidptr(var)} <- ${value}')
13 unsafe {
14 *var = value
15 }
16}
17
18fn test_generic_over_a_local_boolean_address() {
19 eprintln('-'.repeat(40))
20 mut mybool := false
21 println(mybool)
22 store(mybool, true)
23 println(mybool)
24 eprintln('-'.repeat(40))
25}
26
27fn test_generic_over_a_const_returned_by_a_fn() {
28 println(current().aborted)
29 store(current().aborted, true)
30 println(current().aborted)
31 eprintln('-'.repeat(40))
32}
33